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
| Function | Moves the dates to | Example measure |
|---|---|---|
TOTALYTD | 1 January up to the end of the row's period | Revenue YTD |
SAMEPERIODLASTYEAR | The same dates, one year earlier | Revenue LY |
DATEADD | The dates shifted by a number of days, months, quarters or years | Revenue PM |
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.
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 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.
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
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 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.
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.
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 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.
2024 is above 2023 in every month. Year to date at December: ₦88,797,696 against ₦57,056,529, growth of +55.6%.
Measures build on measures here too: Revenue YTD LY is Revenue YTD with the dates moved back a year.
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
- Check the Date table is marked and related.
- Write Revenue YTD, Revenue LY, Revenue YoY %, Revenue PM and Revenue MoM %, and format them.
- Build the 2024 matrix and check every number against this lesson.
- Select 2023 and explain the blanks to yourself.
- Build the this-year-against-last-year line chart.
- 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.