Since we just built our Master Calendar, today we move to the most famous “Basic” skill in Power BI: Time Intelligence (DAX).
This is the ability to compare different time periods. In Excel, comparing “This Month vs. Last Month” requires a lot of manual copying and pasting. In Power BI, we use two simple formulas to do it automatically.
Today’s topic is The “Big Two” Time Formulas: TOTALYTD and SAMEPERIODLASTYEAR.
Why These Formulas are Essential
Business owners rarely ask “How much did we make today?” They usually ask:
- “How are we doing so far this year?” (Year-to-Date)
- “Are we doing better than we were this time last year?” (Year-over-Year)
If you don’t have a Calendar Table (which we built yesterday), these formulas will return errors. If you do have one, they are magic.
The Lab Data: Your Sales History
To see this work, you need data that spans at least two years. Create this in Excel and import it:
Table: SalesData
| Date | Revenue |
| :— | :— |
| 01/15/2025 | 1000 |
| 06/10/2025 | 2000 |
| 01/15/2026 | 1500 |
| 02/01/2026 | 500 |
Action Step 1: Calculating Year-to-Date (TOTALYTD)
This formula “adds up” everything from January 1st to the current date.
- The Prep: First, create a basic measure for Total Sales:
Total Sales = SUM(SalesData[Revenue]) - The Action: Right-click your table and select New Measure.
- The Step: Type this formula:$$Sales YTD = TOTALYTD([Total Sales], MasterCalendar[Date])$$
- The Result: Drag this into a Card. It will show $2,000 (The sum of the 2026 sales so far). If you filter for 2025, it will show $3,000.
Action Step 2: Comparing to Last Year (SAMEPERIODLASTYEAR)
This is the “Time Machine” formula. It tells Power BI to look at the current date and “jump back” exactly one year.
- The Action: Right-click your table and select New Measure.
- The Step: Type this formula:$$Sales Last Year = CALCULATE([Total Sales], SAMEPERIODLASTYEAR(MasterCalendar[Date]))$$
- The Result: Create a Table Visual.
- Drag
MasterCalendar[Month]andMasterCalendar[Year]into it. - Drag
[Total Sales]and[Sales Last Year]into it.
- Drag
- Observation: Look at the row for January 2026. You will see $1,500 in the Total Sales column, and $1,000 in the Sales Last Year column.
The “Basics” Checklist for Time Intelligence
- Requirement: Your Calendar Table must be connected to your Sales Table.
- The “Measure” Rule: Always use a Measure (like
Total Sales) inside these formulas, not a raw column. - The Date Trigger: Always use the
Datecolumn from your MasterCalendar, not the one from your Sales table.
Your Action Summary
- Create the Total Sales measure.
- Create the Sales YTD measure to see cumulative growth.
- Create the Sales Last Year measure to compare performance.
- Put them all in a Line Chart to see “This Year” vs “Last Year” as two separate lines.
Leave a Reply