cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sofie Frequent Visitor
Frequent 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? Smiley Happy

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
mnayar Established Member
Established Member

Re: Date difference customer orders

@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

3 REPLIES 3
SPG Member
Member

Re: Date difference customer orders

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

Highlighted
Sofie Frequent Visitor
Frequent Visitor

Re: Date difference customer orders

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

 

mnayar Established Member
Established Member

Re: Date difference customer orders

@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

Helpful resources

Announcements
Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Summit Australia 2019

Summit Australia 2019

Travel to Melbourne and network with thousands of peers!

PBI Community Highlights

PBI Community Highlights

Check out what's new in the Power BI Community!

Top Ideas
Users Online
Currently online: 28 members 844 guests
Please welcome our newest community members: