cancel
Showing results for
Did you mean:
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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
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

3 REPLIES 3
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

Frequent Visitor

## Re: Date difference customer orders

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

Highlighted
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

Announcements

#### Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

#### Community News & Announcements

Get your latest community news and announcements.

#### Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

#### Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Top Kudoed Authors
Users Online
Currently online: 44 members 939 guests
Recent signins: