Module 6 · Power BI DAX
Time intelligence
Year-to-date, same period last year, month-on-month and rolling totals, plus the like-for-like fix that stops a part year from looking like a collapse.
About 25 minutes
The problem
Kolanut's board pack has a KPI card: "Revenue 2026: ₦290.7m, −46.1% vs last year." The board is alarmed. In fact revenue is up 19.1% on the same months of last year. The data runs only to 30 June 2026, so the card compared six months with twelve.
Time comparisons are what managers ask for most: this year so far, against last year, against last month, the last three months. DAX has a family of time intelligence functions that make them short to write, but they only give honest answers if the date table is right and you handle incomplete periods deliberately.
The concept
Prerequisites
Time intelligence functions work on a proper date table: one row per day with no gaps, covering whole years, marked as a date table, and related to the fact table. You built exactly that in lesson 1.
The core functions
Each one returns a set of dates, which you use as a filter in CALCULATE:
| Function | Dates returned, for the current filter |
|---|---|
DATESYTD ( 'Date'[Date] ) | 1 January up to the last date in the filter |
DATESQTD, DATESMTD | the same, from the start of the quarter or month |
SAMEPERIODLASTYEAR ( 'Date'[Date] ) | the same dates, one year earlier |
DATEADD ( 'Date'[Date], -1, MONTH ) | the same dates shifted by any number of days, months, quarters or years |
DATESINPERIOD ( 'Date'[Date], <end>, -3, MONTH ) | a window of 3 months ending on a given date |
DAX
Revenue YTD = CALCULATE ( [Revenue], DATESYTD ( 'Date'[Date] ) )
Revenue LY = CALCULATE ( [Revenue], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
Revenue PM = CALCULATE ( [Revenue], DATEADD ( 'Date'[Date], -1, MONTH ) )
MoM % = DIVIDE ( [Revenue] - [Revenue PM], [Revenue PM] )
Revenue Rolling 3M =
CALCULATE (
[Revenue],
DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, MONTH )
)TOTALYTD ( [Revenue], 'Date'[Date] ) is a shortcut for the YTD measure. For a financial year ending 30 June, DATESYTD ( 'Date'[Date], "30/6" ) restarts the count each 1 July.
The incomplete-year trap
At year level, the 2026 filter contains every date from 1 January to 31 December 2026, because the date table covers whole years. SAMEPERIODLASTYEAR shifts that to the whole of 2025, and you're comparing six months of sales with twelve.
The fix is to limit the current period to dates that have sales before shifting. Add a calculated column to the date table:
DAX
Date With Sales = 'Date'[Date] <= MAX ( orders[order_date] )In a calculated column there's no filter on orders, so MAX ( orders[order_date] ) is the last sale overall: 30 June 2026. Then:
DAX
Revenue LY (like for like) =
CALCULATE (
[Revenue],
CALCULATETABLE (
SAMEPERIODLASTYEAR ( 'Date'[Date] ),
'Date'[Date With Sales] = TRUE ()
)
)CALCULATETABLE first trims the current dates to those up to 30 June 2026, and then SAMEPERIODLASTYEAR shifts them back a year. At year level, 2026 is now compared with January to June 2025.
Example
A matrix with Date[Year] and Date[Month] in Rows:
| Row | Revenue | Revenue LY (like for like) | YoY % |
|---|---|---|---|
| 2026 | 290,730,455 | 244,163,070 | 19.1% |
| 2026 Apr | 54,580,085 | 44,634,720 | 22.3% |
| 2026 May | 46,767,400 | 40,251,060 | 16.2% |
| 2026 Jun | 46,173,840 | 39,767,970 | 16.1% |
With the plain Revenue LY, the 2026 row would show ₦539.8m and −46.1%. The monthly rows are identical with either measure. The trap only appears on rows that include dates with no sales yet.
Walkthrough
- Add
Revenue YTD,Revenue LY,Revenue PM,MoM %andRevenue Rolling 3M. Format the percentages with one decimal place. - Build the matrix from the example with
[Revenue],[Revenue LY]and aYoY %measure:DIVIDE ( [Revenue] - [Revenue LY], [Revenue LY] ). Find the −46.1% on the 2026 row. - Add the
Date With Salescolumn andRevenue LY (like for like), and changeYoY %to use it. The 2026 row becomes +19.1%. - Add
Revenue YTDto the matrix and check that it restarts at January 2026. - Put
Revenue Rolling 3Mon a line chart byDate[Year Month]. It smooths out December 2025's festive peak, which is why managers like rolling figures for spotting trends.
Practice
Practice
What is Revenue YTD at the end of May 2026? (A rounded figure is fine.)
Practice
What is Revenue Rolling 3M at June 2026? (A rounded figure is fine.)
Practice
What is MoM % for June 2026? One decimal place (it's negative).
Challenge
Challenge · optional
6 minWrite Revenue YTD LY (like for like): last year's year-to-date revenue, limited to the same dates that have sales this year. Build on the measures from this lesson. Paste it here.
Your work is checked for
- Named Revenue YTD LY (like for like)
- Uses SAMEPERIODLASTYEAR or DATEADD with -1 YEAR
- Is year-to-date: DATESYTD, TOTALYTD or [Revenue YTD]
- Limits to dates with sales
More practice
Drill · optional
Legal data: build a date table for 2024 to 2026 related to invoices[issued_date], and a Billed measure. What is Billed LY (like for like) for 2026, given invoices run to the end of August 2026? (A rounded figure is fine.)
Check your understanding
Answer every question to check.