Forum Discussion

Sofie's avatar
Sofie
Regular Visitor
7 years ago
Solved

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...
  • Anonymous's avatar
    Anonymous
    7 years ago

    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