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
Sofie
Regular Visitor

Date difference customer orders

Hi,

 

I want to calculate the number of days between today and the last time a customer made a purchase order. I have a table with the purchase order nr as key and then the customer nr and purchase date. For every customer I want to know how long it has been since his last puchase. I tried to make a measure with the datedifference function but it never gives the correct result. Does anybody knows how to do this? 🙂

 

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Sofie

Calculate Max Order Date Per Customer using ALLEXCEPT and then calculate Datediff with today.

 

Time Since Last Order Date =

Var LastOrderDt = CALCULATE(MAX('P6:TimeSinceLastOrder'[OrderDate]), ALLEXCEPT('P6:TimeSinceLastOrder','P6:TimeSinceLastOrder'[CustomerId]))

Var TimeSinceLastOrderDt = DATEDIFF(LastOrderDt,TODAY(),DAY)

RETURN TimeSinceLastOrderDt

Challenge - TimeSinceLastOrder.PNG

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

@Sofie

Calculate Max Order Date Per Customer using ALLEXCEPT and then calculate Datediff with today.

 

Time Since Last Order Date =

Var LastOrderDt = CALCULATE(MAX('P6:TimeSinceLastOrder'[OrderDate]), ALLEXCEPT('P6:TimeSinceLastOrder','P6:TimeSinceLastOrder'[CustomerId]))

Var TimeSinceLastOrderDt = DATEDIFF(LastOrderDt,TODAY(),DAY)

RETURN TimeSinceLastOrderDt

Challenge - TimeSinceLastOrder.PNG

Anonymous
Not applicable

Create this measure:

 

Days Since Last Order = DATEDIFF(MAX(Sales[OrderDate]), TODAY(), DAY)

Then use it in a table with the customer key or name

This does not seems to work if I try to adjust the current date

 

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.