DATESINPERIOD
DATESINPERIOD is a DAX function used in Power BI, Analysis Services, and Power Pivot to return a table of dates from a date column that fall within a specific period. The period is anchored at StartDate and spans a number of intervals at a chosen granularity such as day, week, month, quarter, or year.
Syntax: DATESINPERIOD (Dates, StartDate, NumberOfIntervals, Interval)
- Dates: a column of date values that defines the valid date domain, typically from a Date table.
- StartDate: a scalar date that serves as the anchor for the period.
- NumberOfIntervals: an integer specifying how many intervals to include. A negative value looks backward from StartDate;
- Interval: the interval granularity; options include DAY, WEEK, MONTH, QUARTER, or YEAR.
Return: a one-column table containing the dates from Dates that lie within the defined period, inclusive where
Usage notes: DATESINPERIOD is a common tool for time-intelligence calculations, enabling calculations such as “last N
- Last 12 months ending at the latest date: CALCULATE(SUM(Sales[Amount]), DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -12, MONTH))
- Next 30 days from today: DATESINPERIOD('Date'[Date], TODAY(), 30, DAY)