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

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

Reply
seanpratt291
Frequent Visitor

Need help with two columns for days between dates

I need two help with two columns here - hoping it's not a major issue. 

 

Essentially what I need to do is understand two things

1) What is the time between the same product being purchased by the same user? That is "Days Since Last Purchase of this product". For the Purchase # of 1, it's null - but for the second purchase it's the days between purchase #2 and purchase #1. The same logic applies down the column, but it'll reset for each Customer. I'm using this to determine for products that have repeat purchases, what's the average days before a purchase is made again on that same product.

 

2) Very similar logic but it's simply for order #. I just want to understand the average days between repeat customers placing an order, regardless of what they're ordering.

 

I hope that's clear. This is the current set up of my table and the two columns on the right are what I need either help with or a workaround solution!

 

Thank you!

 

Capture.PNG

1 ACCEPTED SOLUTION

Hi,

These calculated column formulas work

Days Since Last Purchase of Product = if(ISBLANK(CALCULATE(MAX(Data[Order Date]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])&&Data[Purchase #]<EARLIER(Data[Purchase #])))),BLANK(),Data[Order Date]-CALCULATE(MAX(Data[Order Date]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])&&Data[Purchase #]<EARLIER(Data[Purchase #]))))
Days Since Last order = if(ISBLANK(CALCULATE(MAX(Data[Order Date]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])&&Data[Order #]<EARLIER(Data[Order #])))),BLANK(),Data[Order Date]-CALCULATE(MAX(Data[Order Date]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])&&Data[Order #]<EARLIER(Data[Order #]))))

Hope this helps.

Untitled.png

 


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

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Let's only look at the result in the second last column.  In that column, what result are you expecting for row 4(Order ID 772).  should the result be [Nov 2 - Oct 15] or [Nov 2 - Sep 27].  Share your expected result in a simple MS Excel file so that your Excel formulas can be translated into the DAX language.

Also, do you want a calculated column formula solution or a measure solution?


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

Hi there,

 

Here's the link to it
https://www.dropbox.com/scl/fi/anohgfg9wja61zo7osri2/Book1.xlsx?dl=0&rlkey=k8wid6bq03ur79jtab7j1obq7

 

Essentially I need the second last column to always be the time between the current order date and the LAST order date, not the FIRST order date.

The same logic applies to the very last column, but instead of using the 'Days Since Last Purchase' column, you use the "Days Since Last Order"

Hi,

These calculated column formulas work

Days Since Last Purchase of Product = if(ISBLANK(CALCULATE(MAX(Data[Order Date]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])&&Data[Purchase #]<EARLIER(Data[Purchase #])))),BLANK(),Data[Order Date]-CALCULATE(MAX(Data[Order Date]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])&&Data[Purchase #]<EARLIER(Data[Purchase #]))))
Days Since Last order = if(ISBLANK(CALCULATE(MAX(Data[Order Date]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])&&Data[Order #]<EARLIER(Data[Order #])))),BLANK(),Data[Order Date]-CALCULATE(MAX(Data[Order Date]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])&&Data[Order #]<EARLIER(Data[Order #]))))

Hope this helps.

Untitled.png

 


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

Amazing! That worked perfectly 🙂 Thank you!

You are welcome.


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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.