Days since last purchase (recency) with DATEDIFF

Count the days between each customer’s most recent purchase and the end of the selected period, a recency score that flags customers going quiet.

You will learn to

  • Use the last date of the period as “today”
  • Find the last purchase up to that date, even before the period
  • Count the days between two dates with DATEDIFF

How it works

**Recency**, the days since a customer last bought, is the strongest early warning of churn: the longer the silence, the less likely they come back. It is the R in RFM analysis.

The data is fixed, so “today” is the **last date of the selected period**: `MAX('Date'[Date])`. A Customer row doesn’t filter the Date table, so this is the end of the slicer’s period for every customer.

The last purchase must look back beyond the period: a customer who skipped December still has a last purchase, in November or earlier. `DATESBETWEEN('Date'[Date], BLANK(), LastDay)` is every date from the start of the calendar (a blank start means “from the first date”) up to the end of the period. Used as a CALCULATE filter it replaces the slicer’s dates, so `MAXX(Sales, RELATED('Date'[Date]))` sees the customer’s whole history up to that day. (The filter `'Date'[Date] <= LastDay` does the same job.) Then `DATEDIFF(start, end, DAY)` counts the days between the two dates.

Practice it hands-on with a real data model and a live report that updates as you type.

Days Since First Purchase =
VAR LastDay = MAX('Date'[Date])
VAR FirstBuy = CALCULATE(MINX(Sales, RELATED('Date'[Date])), REMOVEFILTERS('Date'))
RETURN DATEDIFF(FirstBuy, LastDay, DAY)