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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jeroenwmwillems
Advocate I
Advocate I

Days between orders of Unique Customers

Hi there,

 

I'm getting stuck with a query and haven't been able to find any answers in previous posts from other users. 

Effectively, I have 2 columns of interest: Date and UserID. I'm trying to calculate the amount of days in between consequtive orders for the individual users. I've made a screenshot of an example file with column 3, days between orders, the desired column to make. (In my actual data, these values are of course not perfectly fitlered like this). 

jeroenwmwillems_0-1705279521139.png

 

Thanks in advance for your wisdom!

 

Cheers,

Jeroen

 

1 ACCEPTED SOLUTION

Hi, You are welcome. Try this =Days between orders = calculate(min(Data[Date]),filter(Data,Data[UserID]=earlier(Data[UserID])&&Data[Date]>earlier(Data[Date])))-Data[Date] Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @jeroenwmwillems

 

Please follow these steps:

1.Create a new calculation column and write

 

Days between orders = DATEDIFF(calculate(max('Table'[Date]),filter('Table','Table'[UserID]=earlier('Table'[UserID])&&'Table'[Date]<earlier('Table'[Date]))),'Table'[Date],DAY)

 

 

vkaiyuemsft_1-1705307971047.png

2.The results obtained are as follows

 

vkaiyuemsft_0-1705308133964.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula

Days between orders = Data[Date]-calculate(max(Data[Date]),filter(Data,Data[UserID]=earlier(Data[UserID])&&Data[Date]<earlier(Data[Date])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks heaps for this Ashish, this did exactly what I asked. 

I discovered I made a mistake in my logic however, as I am actually trying to see how many days it took for a customer to order again after a certain event. Therefore, my end result should ideally look like this:

jeroenwmwillems_0-1705365502283.png

 

Would there be a way of tweaking the fomula to get this as a result? 

 

Thanks again for your help!

Hi, You are welcome. Try this =Days between orders = calculate(min(Data[Date]),filter(Data,Data[UserID]=earlier(Data[UserID])&&Data[Date]>earlier(Data[Date])))-Data[Date] Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks Ashish, incredible!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.