Power Pivot & DAX course · Lesson 12 of 16

Time intelligence in DAX: TOTALYTD, SAMEPERIODLASTYEAR, DATEADD, DATESINPERIOD

Year-to-date, last year, month-on-month and rolling three-month measures in Power Pivot, with a marked date table and checked results.

Advanced 22 min read

Comparing periods is what most managers ask for first: How are we doing year to date? Is this month better than the same month last year? What is the trend over the last three months? DAX has a set of time-intelligence functions that answer these questions in one line each. They all work by shifting or extending the dates in the filter context, and they all rely on a proper calendar table, built in Building a calendar (date) table for Power Pivot.

Watch out. Time-intelligence functions need a marked date table: a Calendar table with one row per day for complete years, related to the fact table and marked with Design › Mark as Date Table in the Power Pivot window. Without it, results are missing or wrong, especially when you filter by month or year columns of the calendar.

The data

This lesson uses a slightly different Sales table that covers two years, so there is something to compare with. It is related to the same Products table and to a Calendar table covering 2025 and 2026 by Sales[OrderDate] → 'Calendar'[Date].

ABCD
1OrderDateProductIDQtyAmount
22025-01-14P11950
32025-02-10P32378
42025-02-25P215180
52025-03-18P121900
62025-04-07P44140
72026-01-09P121900
82026-01-22P51420
92026-02-16P33567
102026-03-05P225300
112026-03-27P52840
122026-04-14P11950

Sales for January–April of 2025 and 2026. Amount = Qty × Price.

The measures

DAX
Revenue := SUM ( Sales[Amount] )

Revenue YTD := TOTALYTD ( [Revenue], 'Calendar'[Date] )

Revenue LY := CALCULATE ( [Revenue], SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) )

YoY % := DIVIDE ( [Revenue] - [Revenue LY], [Revenue LY] )

Rolling 3M :=
CALCULATE (
    [Revenue],
    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -3, MONTH )
)
Five measures. Always pass the Date column of the calendar, never Sales[OrderDate].
ABCDEF
1MonthRevenueRevenue YTDRevenue LYYoY %Rolling 3M
2Jan23202320950144.2%2320
3Feb56728875581.6%2887
4Mar114040271900-40.0%4027
5Apr9504977140578.6%2657
6Grand Total49774977354840.3%2657

'Calendar'[Month] on rows, Year slicer = 2026, months Jan–Apr shown. YoY % with 1 decimal.

Year to date: TOTALYTD

TOTALYTD ( expression, dates ) evaluates the expression from 1 January to the last date in the current filter context. In the March row, the dates in context are 1–31 March 2026, so the measure uses 1 January–31 March: 2,320 + 567 + 1,140 = 4,027. It is a shorthand for:

DAX
Revenue YTD := CALCULATE ( [Revenue], DATESYTD ( 'Calendar'[Date] ) )
DATESYTD returns the dates from the start of the year; CALCULATE applies them.

For a fiscal year, add the year-end date as text: TOTALYTD ( [Revenue], 'Calendar'[Date], "6/30" ) runs the year from 1 July to 30 June. TOTALQTD and TOTALMTD (with DATESQTD and DATESMTD) work the same way for quarters and months.

Same period last year: SAMEPERIODLASTYEAR and DATEADD

SAMEPERIODLASTYEAR ( dates ) takes the dates in the current filter context and moves each one back one year. In the February 2026 row it returns 1–28 February 2025, so Revenue LY shows February 2025's 558 (a monitor order and a mouse order). Growth is then 567 − 558 divided by 558 = 1.6%.

DATEADD is the more general version: it shifts the dates by any number of days, months, quarters or years, forwards or backwards.

DAX
Revenue LY (DATEADD) := CALCULATE ( [Revenue], DATEADD ( 'Calendar'[Date], -1, YEAR ) )
Revenue Prev Month := CALCULATE ( [Revenue], DATEADD ( 'Calendar'[Date], -1, MONTH ) )
MoM % := DIVIDE ( [Revenue] - [Revenue Prev Month], [Revenue Prev Month] )
DATEADD ( dates, number_of_intervals, DAY | MONTH | QUARTER | YEAR ).

Revenue LY (DATEADD) returns exactly the same values as Revenue LY. Revenue Prev Month in the March row returns February: 567, so MoM % is 101.1%. In the January row it looks at December 2025, which had no sales, so it is blank and DIVIDE returns blank instead of an error.

Note. Related functions: PREVIOUSMONTH, PREVIOUSQUARTER and PREVIOUSYEAR return the whole previous period regardless of how many days are selected; PARALLELPERIOD ( dates, -1, YEAR ) also returns the whole parallel year. SAMEPERIODLASTYEAR and DATEADD keep the exact shape of the selection, which is usually what a like-for-like comparison needs.

Moving windows: DATESINPERIOD

DATESINPERIOD ( dates, start_date, number_of_intervals, interval ) returns a block of dates counted from a start date. With MAX ( 'Calendar'[Date] ) as the start and -3, MONTH, it returns the three months ending on the last visible date. In the April row that is February to April: 567 + 1,140 + 950 = 2,657. In the January row the window covers November 2025 to January 2026, and since there were no sales in November and December the result equals January's 2,320.

Divide the rolling sum by 3 for a three-month moving average, or use -12, MONTH for a rolling annual total, which smooths out seasonality and is a favourite on management dashboards.

Reading the Grand Total row

The totals follow the same rules with a larger filter context: 1 January–30 April 2026. Revenue YTD uses the last date (30 April), so it equals the four-month revenue 4,977. Revenue LY shifts the whole block back a year (3,548), giving 40.3% growth. Rolling 3M looks at the three months ending 30 April, not at all four months: 2,657. Totals of moving windows rarely mean much; you may prefer to hide them with IF ( HASONEVALUE ( 'Calendar'[Month] ), ... ).

Common problems

  • Blank or wrong results: the calendar is not marked, has gaps, or does not cover complete years. Check with COUNTROWS ( 'Calendar' ): 730 for 2025–2026.
  • Using the fact table's date: SAMEPERIODLASTYEAR ( Sales[OrderDate] ) only contains dates with sales, so periods with no sales cannot be shifted onto. Always use 'Calendar'[Date].
  • Future months showing YTD values: in May–December 2026 there is no revenue, but Revenue YTD repeats the April figure, so those months appear in the PivotTable. Hide them with IF ( NOT ISBLANK ( [Revenue] ), TOTALYTD ( [Revenue], 'Calendar'[Date] ) ) or filter the months.
  • Comparing a partial year with a full year: if this year ends in April, a Year-level comparison with the whole of last year is unfair. Limit last year to the same dates, as the Grand Total above does automatically when the months are filtered.
Tip. Put 'Calendar'[Year] in a slicer and 'Calendar'[Month] on rows, sorted by MonthNo. This layout makes every time-intelligence measure easy to read and check. The next lesson, Variables, DIVIDE and error handling in DAX, shows how to make growth measures robust when last year is blank.

Check yourself

1. Which table must time-intelligence functions use for their dates argument?

2. What does TOTALYTD ( [Revenue], 'Calendar'[Date] ) return in the March row?

3. Which expression returns the same values as SAMEPERIODLASTYEAR for a month?

4. What does DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -3, MONTH ) return in the April row?

5. How do you run a fiscal year from 1 July?