DAX function
DATESINPERIOD — DAX function reference
A rolling window of dates.
Syntax
dax
DATESINPERIOD(<dates>, <start_date>, <number_of_intervals>, <interval>)
Examples
dax
CALCULATE(SUM(Sales[Amount]), DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -3, MONTH))→ Rolling 3-month value
dax
CALCULATE(SUM(Sales[Amount]), DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -12, MONTH))→ Trailing 12-month sales, anchored to the last date in context
DATESINPERIOD supplies the window of dates and AVERAGEX evaluates the daily total for each before averaging.
dax
AVERAGEX(DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -7, DAY), CALCULATE(SUM(Sales[Amount])))→ A 7-day moving average of daily sales
Common mistakes & gotchas
- The window anchors to start_date and extends backward (negative count) or forward (positive) — using MAX('Date'[Date]) as the anchor is essential so the window follows whatever date is currently selected, not a hardcoded date.
- Unlike DATESYTD/SAMEPERIODLASTYEAR, DATESINPERIOD doesn't require the date table to start at a period boundary, making it the right choice for genuinely rolling (not calendar-aligned) windows like trailing-N-days.
Related DAX functions
From Time intelligence