Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
erocco
Frequent Visitor

Counting based on rolling time

Hi!

 

I have 3 tables: 1 (Visits) with details when a customer was visited, 1 (Orders) with details of when & how much customers order, 1 calendar table linking them both by date (one to many, to date of visit, to date of order), one customer ID table linkinking both (one to many). 

 

I would like to create a measure where I can count if a customer was visited and created an order 7 days after the visit (or earlier).

 

I haven't been able to figure out what logic to use to approach this, so any help would be greatly appreciated! Most I was able to do was a distinct count of the customer ID in Visits filtering the Order table by Order Amount >0. But I have no idea how to do this in a rolling way and specific to the Visit Date.

 

I don't have easy access to the underlying dataset so can't manipulate it directly.

1 ACCEPTED SOLUTION
isabella
Employee
Employee

Hi @erocco 

You can do this in power query,I did a local test,you can take a reference,hope this helps.

 

1.First open the power query by click the Transform data button

isabella_0-1652172135741.png

 

 

  1. then merge ordertable and visittable  by the same feild "CustomerFSFAID" ,choose the Merge Queries as New,so it would not affect the origin table,it is to create a new table.

 

isabella_1-1652172135742.png

 

isabella_2-1652172135744.png

 

 

Here I want to inform you that,I choose the left outer join,it means all the left table data will be reserved even if there is no match.

3.Then expand the visit table all column

isabella_3-1652172135745.png

 

 

 

4.Then create a custom column   to calculate days between the two dates

 

use expression :=Duration.Days([CreatedDateID]-[CallDateID])

 

about how to calculate the date diff between two dates,please refer to this thread:https://www.pettakatechnologies.com/calculate-difference-between-dates-in-power-query/#:~:text=%20Ca...

 

 

isabella_4-1652172135747.png

 

now there is a column "Duration" in the merged table

isabella_5-1652172135748.png

 

5.Then we can filter the table base on this column

isabella_6-1652172135749.png

 

isabella_7-1652172135750.png

 

 

then the table has only 1 row left,I think the column CustomerFSFAID  is what you need.

isabella_8-1652172135759.png

 

 

At last ,you can press the left-top button “close & apply” to close the power query.

isabella_9-1652172135760.png

 

Best Regards,

Community Support Team _Isabella

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Does this help with your problem?

All customers place an order on the same date as visit, except for customer 666, who takes 1 year to place order after visit, so he is not counted.

Nij_0-1652943015095.png

 

isabella
Employee
Employee

Hi @erocco 

Has your problem been solved, if so, please consider Accept a correct reply as the solution or share your own solution to help others find it.

 

Best Regards

Community Support Team _Isabella

isabella
Employee
Employee

Hi @erocco 

You can do this in power query,I did a local test,you can take a reference,hope this helps.

 

1.First open the power query by click the Transform data button

isabella_0-1652172135741.png

 

 

  1. then merge ordertable and visittable  by the same feild "CustomerFSFAID" ,choose the Merge Queries as New,so it would not affect the origin table,it is to create a new table.

 

isabella_1-1652172135742.png

 

isabella_2-1652172135744.png

 

 

Here I want to inform you that,I choose the left outer join,it means all the left table data will be reserved even if there is no match.

3.Then expand the visit table all column

isabella_3-1652172135745.png

 

 

 

4.Then create a custom column   to calculate days between the two dates

 

use expression :=Duration.Days([CreatedDateID]-[CallDateID])

 

about how to calculate the date diff between two dates,please refer to this thread:https://www.pettakatechnologies.com/calculate-difference-between-dates-in-power-query/#:~:text=%20Ca...

 

 

isabella_4-1652172135747.png

 

now there is a column "Duration" in the merged table

isabella_5-1652172135748.png

 

5.Then we can filter the table base on this column

isabella_6-1652172135749.png

 

isabella_7-1652172135750.png

 

 

then the table has only 1 row left,I think the column CustomerFSFAID  is what you need.

isabella_8-1652172135759.png

 

 

At last ,you can press the left-top button “close & apply” to close the power query.

isabella_9-1652172135760.png

 

Best Regards,

Community Support Team _Isabella

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

erocco
Frequent Visitor

Here's some sample data:

Call (visit) table:

erocco_0-1652078146985.png

Order table:

erocco_1-1652078170414.png

Calendar table:

erocco_2-1652078183161.png

CustomerID table:

erocco_3-1652078193921.png

 

 

 

ribisht17
Super User
Super User

@erocco 

 

Please post some sample data to get quick answers

 

 

Regards,

Ritesh

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.