Courses Learn Blog Contact
Get Started →
Lesson 16

Day 12: Time Intelligence

Year to date, same period last year, growth and month-on-month, all resting on a Date table.

Webbo3 Power BI Cohort 1 9 min read Free

Webbo3 Power BI · Cohort 1 · Day 12 of 16

Day 12: Time Intelligence

Year to date, the same period last year, and growth, calculated by Power BI from the calendar instead of years you type in.

By the end of today you can

  • Say what time intelligence is and why it needs a marked Date table
  • Write a year-to-date measure with TOTALYTD
  • Compare with last year using SAMEPERIODLASTYEAR
  • Compare with last month using DATEADD
  • Build year-on-year and month-on-month growth, and read their blanks correctly

On Day 11 you typed 2024 into a measure. It worked until January. Time intelligence measures work out "this year", "last year" and "last month" from whatever dates the reader is looking at.

Open your Day 11 file. Check two things before you start: the Date table is marked as a date table (Table tools, Mark as date table), and it is related to Sales[Date]. Every function today depends on both.

1. What Time Intelligence Is

Definition

Time intelligence functions are DAX functions that change the dates a measure is calculated over: from the start of the year, back one year, back one month. They are used inside CALCULATE, or come with CALCULATE built in.

Real-Life Example

Your bank app shows "spent this month" and "spent last month" side by side. You never tell it which month is last month; it works it out from today. Time intelligence does that for a report: it works out "last year" from whichever dates are on the row.

Why It Needs the Date Table

The functions walk along a calendar: back 365 days, forward to the end of the month. That only works on a table with every date, no gaps and no repeats, which is exactly the Date table from Day 7. Sales [Date] has repeats (many sales a day) and may have gaps (a day with no sales), so always point time intelligence at 'Date'[Date].

Types

FunctionMoves the dates toExample measure
TOTALYTD1 January up to the end of the row's periodRevenue YTD
SAMEPERIODLASTYEARThe same dates, one year earlierRevenue LY
DATEADDThe dates shifted by a number of days, months, quarters or yearsRevenue PM
Picture This

Picture the bank app counting back from today, so you never have to say which month you mean.

2. Year to Date: TOTALYTD

Definition

Year to date (YTD) is the running total from 1 January to the end of the period you are looking at. On the March row it is January plus February plus March.

Real-Life Example

A savings target for the year: by March you want to know not what you saved in March, but everything saved since New Year.

What this code doesWe want revenue from 1 January to the end of each month of 2024, with Date[Month] on the rows of a matrix and 2024 selected.
Measure
1
2
3
4
5
6
// Running total from 1 January, restarting every year
Revenue YTD =
TOTALYTD (
    [Total Revenue],   // what to add up
    'Date'[Date]       // the calendar to walk along
)
Matrix: 2024 by month
MonthTotal RevenueRevenue YTD
Jan₦6,638,182₦6,638,182
Feb₦7,172,787₦13,810,969
Mar₦6,211,792₦20,022,761
Apr₦6,675,666₦26,698,427
May₦5,960,733₦32,659,160
Jun₦7,137,024₦39,796,184
Jul₦8,743,315₦48,539,499
Aug₦8,150,791₦56,690,290
Sep₦7,563,872₦64,254,162
Oct₦7,618,137₦71,872,299
Nov₦8,164,641₦80,036,940
Dec₦8,760,756₦88,797,696
Total₦88,797,696₦88,797,696

December's YTD equals the year's total, and so does the total row: the "year to date" of the whole year is the whole year. Put 2023 on the page as well and the YTD column restarts at January 2023's figure.

Picture This

Picture the savings jar you never empty until New Year.

3. Last Year: SAMEPERIODLASTYEAR

Definition

SAMEPERIODLASTYEAR ( 'Date'[Date] ) takes the dates the row is looking at and moves every one of them back a year. Inside CALCULATE, it gives the measure for the same period last year.

Real-Life Example

A shop comparing this December with last December, not with November. December is always busy, so only last December tells you whether this one was good.

What this code doesWe want each month of 2024 beside the same month of 2023, and the growth between them.
Two measures
1
2
3
4
5
6
7
8
9
10
// The same months, one year earlier
Revenue LY =
CALCULATE (
    [Total Revenue],
    SAMEPERIODLASTYEAR ( 'Date'[Date] )
)

// Growth against last year; blank when there is no last year
Revenue YoY % =
DIVIDE ( [Total Revenue] - [Revenue LY], [Revenue LY] )
Matrix: 2024 by month
MonthTotal RevenueRevenue LYRevenue YoY %
Jan₦6,638,182₦3,116,992+113.0%
Feb₦7,172,787₦2,589,019+177.0%
Mar₦6,211,792₦3,918,251+58.5%
Apr₦6,675,666₦2,956,298+125.8%
May₦5,960,733₦2,830,260+110.6%
Jun₦7,137,024₦5,000,202+42.7%
Jul₦8,743,315₦5,665,293+54.3%
Aug₦8,150,791₦6,143,886+32.7%
Sep₦7,563,872₦6,503,530+16.3%
Oct₦7,618,137₦6,361,183+19.8%
Nov₦8,164,641₦6,085,019+34.2%
Dec₦8,760,756₦5,886,596+48.8%
Total₦88,797,696₦57,056,529+55.6%

Feb grew the most and Sep the least. Look at the 2023 petrol price from Day 9: it jumped in June 2023, so from June the comparison is against the new price, and every month from June grows less than every month before it. Time intelligence gave you the numbers; the business gave you the reason.

The Blank Is Correct

What this visual showsWe want the same matrix with 2023 selected instead, to see what last year means when there is no last year.
Matrix: 2023 by month
MonthTotal RevenueRevenue LYRevenue YoY %
Jan₦3,116,992
Feb₦2,589,019
Mar₦3,918,251
......
Total₦57,056,529

The data starts in January 2023, so there is no 2022 to compare with. Revenue LY is blank, and DIVIDE turns the growth into blank instead of an error. A blank here is the honest answer, not a broken measure.

Picture This

Picture this December and last December side by side, and an empty space where there was no shop the year before.

4. Last Month: DATEADD

Definition

DATEADD ( 'Date'[Date], -1, MONTH ) moves the row's dates by a number of units: here minus one month. The units can be DAY, MONTH, QUARTER or YEAR. Minus goes back, plus goes forward.

Real-Life Example

The bank app's "compared with last month". Useful for spotting a sudden drop quickly, before a whole year has passed.

What this code doesWe want each month of 2024 beside the month before it. January 2024 compares with December 2023.
Two measures
1
2
3
4
5
6
7
8
9
10
// The previous month's revenue
Revenue PM =
CALCULATE (
    [Total Revenue],
    DATEADD ( 'Date'[Date], -1, MONTH )
)

// Change against the previous month
Revenue MoM % =
DIVIDE ( [Total Revenue] - [Revenue PM], [Revenue PM] )
Matrix: 2024 by month
MonthTotal RevenueRevenue PMRevenue MoM %
Jan₦6,638,182₦5,886,596+12.8%
Feb₦7,172,787₦6,638,182+8.1%
Mar₦6,211,792₦7,172,787-13.4%
Apr₦6,675,666₦6,211,792+7.5%
May₦5,960,733₦6,675,666-10.7%
Jun₦7,137,024₦5,960,733+19.7%
Jul₦8,743,315₦7,137,024+22.5%
Aug₦8,150,791₦8,743,315-6.8%
Sep₦7,563,872₦8,150,791-7.2%
Oct₦7,618,137₦7,563,872+0.7%
Nov₦8,164,641₦7,618,137+7.2%
Dec₦8,760,756₦8,164,641+7.3%

January's previous month is December 2023: DATEADD crosses the year without being told. Month on month jumps about a lot, because busy and quiet months follow each other. That is why managers look at year on year for the trend and month on month for alarms.

Leave the Total Row Out

On the total row, "previous month" of a whole year is only the month before the year starts, so Revenue PM and MoM % are not meaningful there. Turn totals off for this matrix (Format, Row subtotals, off) or leave those two columns off any visual that shows a total.

Picture This

Picture the bank app's little arrow next to this month's spending: up or down on last month.

5. Common Mistakes

  • Using Sales[Date] in the function. Results come out wrong or blank in ways that are hard to spot. Always 'Date'[Date].
  • The Date table is not marked. Some functions still work, some do not. Mark it once and stop wondering.
  • Month on the rows comes from Sales. Rows must come from the Date table too, or the time functions have no dates to move.
  • Reading a blank as a zero. Blank means "nothing to compare with", not "no sales".

6. Putting It Together

The regional manager wants one picture: is 2024 running ahead of 2023, month by month? A line chart with Date[Month] on the X-axis and both Total Revenue and Revenue LY as values, filtered to 2024, draws this year against last year.

What this visual showsWe want this year and last year as two lines, so the gap between them is the growth.
Line chart, 2024 selected

2024 is above 2023 in every month. Year to date at December: ₦88,797,696 against ₦57,056,529, growth of +55.6%.

What this code doesWe want the YTD for the same point last year, to compare "so far this year" fairly in the middle of a year. Checked on June 2024.
Measure
1
2
3
4
5
6
// Year to date, last year: TOTALYTD over last year's dates
Revenue YTD LY =
CALCULATE (
    [Revenue YTD],
    SAMEPERIODLASTYEAR ( 'Date'[Date] )
)
Two cards, June 2024 selected
₦39.8M
Revenue YTD, June 2024
₦39,796,184
₦20.4M
Revenue YTD LY
₦20,411,022

Measures build on measures here too: Revenue YTD LY is Revenue YTD with the dates moved back a year.

Try This

Write Revenue QTD with TOTALQTD, which works exactly like TOTALYTD but restarts every quarter. Put it in the 2024 matrix. What should March's value equal?

Answer: January plus February plus March 2024, ₦20,022,761, the same as Revenue YTD in March, because Q1 starts on 1 January. In April the two part company.

Do This Now

  1. Check the Date table is marked and related.
  2. Write Revenue YTD, Revenue LY, Revenue YoY %, Revenue PM and Revenue MoM %, and format them.
  3. Build the 2024 matrix and check every number against this lesson.
  4. Select 2023 and explain the blanks to yourself.
  5. Build the this-year-against-last-year line chart.
  6. Do the Try This, then carry on with the Solo Project.

Checkpoint

Q1. Why must time intelligence use the Date table, not Sales[Date]?

The functions walk along a calendar and need every date exactly once. Sales[Date] repeats dates and can have gaps.

Q2. What does Revenue YTD show on the December row?

The whole year's revenue, January to December.

Q3. Revenue LY is blank for every month of 2023. Is that a problem?

No. There is no 2022 data, so there is nothing to compare with. Blank is the correct answer.

Q4. How do you write "the same measure, three months earlier"?

CALCULATE with DATEADD ( 'Date'[Date], -3, MONTH ).

Tick Before You Move On

  • ☐ Revenue YTD for December 2024 shows ₦88,797,696
  • ☐ Revenue YoY % for 2024 shows +55.6%
  • ☐ I can explain why 2023 shows blanks in the last-year columns
  • ☐ January 2024 compares with December 2023 in Revenue PM
  • ☐ My line chart shows two lines, 2024 above 2023

Quick Recap

Time intelligence moves the dates a measure is calculated over. It needs a marked Date table, and the dates must come from it. TOTALYTD runs from 1 January; SAMEPERIODLASTYEAR goes back a year; DATEADD moves by any unit. Growth is the change divided by the earlier figure, with DIVIDE. Blank means nothing to compare with.

Final Scenario

It is January 2025. Last year a colleague's report had 2023 and 2024 typed into its measures, and this morning every one of them is out of date.

Yours has none. The reader clicks 2025 and Revenue LY quietly becomes 2024, with not one formula changed.

That is the point of time intelligence: the calendar does the remembering.

Next, Day 13: building visuals. Which chart answers which question, and how to make each one readable. Assignment 3 is released.

Learn this with a real instructor

Free lessons take you a long way on your own. The full programmes add live classes, assignments, Skill Points and a certificate — built for African students.