Introduction
DAX Time Intelligence functions are essential for sales analytics in Power BI. Whether you’re building an executive dashboard or a detailed sales report, comparing performance across time periods helps you uncover trends and make data-driven decisions.
In this guide, you’ll learn three of the most useful DAX functions by using a sample data:
- TOTALYTD — Year-to-date calculations
- SAMEPERIODLASTYEAR — Direct year-over-year comparison
- DATEADD — Flexible period shifting (years, quarters, months)
All examples work in Power BI and SQL Server Analysis Services (SSAS) Tabular. For Excel Power Pivot users, the same formulas apply directly.
What You Need Before Starting
Open Power BI Desktop. Have these two files ready:
- Date_Table.csv — Date dimension with Year, Month, Quarter columns OR create your Date Table using CalendarAuto() and get the associated columns.
- Sales_Data.csv — Sales data with Date, Product, Revenue columns
Part 1: Setting Up Your Data Model
Step 1.1: Import the CSV Files
ACTION: Click Get Data → Text/CSV
- In Power BI Desktop, click Get Data from the ribbon
- Select Text/CSV or File → Text/CSV
- Navigate to the folder you saved the sample datasets and select Date_Table.csv
- Click Load (or Transform Data if you want to preview first)
- Repeat the same steps for Sample_Sales_Data.csv
Step 1.2: Verify Your Data Loaded Correctly
ACTION: Check the tables
- In the left panel, click Data view
- Select Date_Table — verify it shows 25 rows (Jan 2023 to Dec 2024)
- Select Sales — verify it shows 48 rows of transactions

Fig 1: Image showing the table view of the semantic models (Sales and Date_Table dataset)
Step 1.3: Create the Relationship
ACTION: Open Model view and create relationship
- Click Model view (icon in left panel)
- Drag Sales[Date] and drop it onto Date_Table[Date]
- Verify a one-to-many relationship is created (Date_Table on the one side)
- Make sure the relationship is active (solid line, not dashed)

Fig 1.1: Image showing proper data modelling of the semantic models (Sales and Date_Table datasets)
Step 1.4: Mark the Date Table
ACTION: Mark Date_Table as your date dimension
- Right-click on Date_Table in the Fields pane
- Select Mark as date table → Mark as date table
- Choose Date as the date column from the dropdown
- Click OK

Fig 1.2: Image showing how to Mark as date table
Important: Time Intelligence functions require a proper date table marked as a date dimension. Without this, the formulas in this guide won’t work correctly.
Part 2: TOTALYTD — Year-to-Date Calculations
What is TOTALYTD?
TOTALYTD is a DAX function that calculates a cumulative total from the start of the year to the current date in your filter context.
Syntax:
TOTALYTD(<expression>, <dates>, [<filter>], [<year_end_date>]). Now, let’s do it.
Step 2.1: Create the Revenue YTD Measure
ACTION: Create a new measure in the Sales table
- In the Fields pane, right-click on Sales table
- Select New measure
- In the formula bar at the top, type:
Revenue YTD = TOTALYTD(SUM(Sales[Revenue]), Date_Table[Date])
- Press Enter to confirm
Step 2.2: Build a Table Visual to Test
ACTION: Create a table visual
- Click Report view
- In the Visualizations pane, click Table icon
- Drag these fields to the table:
- Date_Table[Month] → Rows
- Revenue YTD → Values

Fig 2.0 Matrix and Card visuals showing the Revenue YTD measure
Step 2.3: Filter to March 2024
ACTION: Apply a filter to see YTD through March
- In the Filters pane, expand Filters on this visual
- Drag Date_Table[Year] to the filter area
- Filter to 2024 only
- Drag Date_Table[Month] to the same filter area
- Filter to 1, 2, 3 (January, February, March)

Fig 2.1: Image showing the filtered Revenue YTD for January to March 2024
Step 2.4: Understand the YTD Calculation
ACTION: Verify the math
Look at the breakdown for March 2024:
- Jan 2024: Widget A (
8,500) = $20,500
- Feb 2024: Widget A (
9,100) = $20,900
- Mar 2024: Widget A (
9,800) = $24,800
- Total YTD through March:
20,900+
66,200

Fig 2.2 Image showing the filtered values between January to March 2024 for validation
Part 3: SAMEPERIODLASTYEAR — Year-over-Year Comparison
What is SAMEPERIODLASTYEAR?
SAMEPERIODLASTYEAR is a time intelligence DAX function that shifts your current date context back by exactly one year, making year-over-year comparisons straightforward.
Syntax:
SAMEPERIODLASTYEAR(<dates>)
Step 3.1: Create the Revenue LY Measure
ACTION: Create a new measure for Last Year revenue
- Right-click on Sales table → New measure
- Enter this formula:
Revenue LY = CALCULATE( SUM(Sales[Revenue]), SAMEPERIODLASTYEAR(Date_Table[Date]))
- Press Enter
Step 3.2: Add Revenue LY to Your Table
ACTION: Add the new measure to the visual
- In your table visual, drag Revenue LY to the Values section (next to Revenue YTD)
- Keep the filter on Year = 2024, Months 1-3

Fig 3.0: Image showing the calculation of the Revenue Last Year
Step 3.3: Compare March 2024 vs March 2023
ACTION: Filter to March only to see the direct comparison
- Change the filter to show only Month = 3 (March)
- Observe that Revenue LY shows March 2023 values

Fig 3.1: Image showing how Revenue Last Year filtered the month of March the previous year (2023)
Calculation for March 2024:
- March 2024: Widget A (15,000)
Widget B (9,800) = $24,800
- March 2023: Widget A (
8,900)
= $26,300
Step 3.4: Add Year-over-Year Growth Percentage
ACTION: Create a YoY Growth % measure
YoY% answers one critical business question: Are we doing better or worse than we were at this exact time last year, and by how much?
- New measure in Sales table:
YoY Growth % = DIVIDE([Revenue YTD] – [Revenue LY], [Revenue LY])
- Add this measure to your table visual

Fig 3.2: Image showing the calculation of YoY% growth with a focus on March 2024
Expected Results for March 2024:
- YoY Growth % = (
26,300) / 26,300 = 1.52%
Part 4: DATEADD — Flexible Period Shifting
What is DATEADD?
DATEADD shifts dates forward or backward by any interval – years, quarters, months, or days. It’s more versatile than SAMEPERIODLASTYEAR though both mean same and can replace one another.
Syntax:
DATEADD(<dates>, <number_of_intervals>, <interval>)
Step 4.1: Create Previous Year Measure with DATEADD
ACTION: Create Revenue PY measure
- New measure in Sales table:
Revenue PY = CALCULATE(SUM(Sales[Revenue]), DATEADD(Date_Table[Date], -1, YEAR))
- Press Enter

Fig 4.0: Image showing the similarity between Revenue PY (DATEADD function) and Revenue LY (SAMEPERIODLASTYEAR function) calculations
Build a Summary Card Visual
ACTION: Create KPI cards for your dashboard
- Click Card visual in Visualizations pane
- Drag Revenue YTD to the card
- Create additional cards for:
- Revenue LY
- YoY Growth %
- Revenue PQ

Part 6: Common Pitfalls and How to Avoid Them
Pitfall 1: Missing Date Table
Problem: Time Intelligence functions require a proper date table.
Solution: If you haven’t marked your date table:
- Right-click Date_Table → Mark as date table → Choose Date column
Pitfall 2: Filter Context Matters
Problem: YTD gives unexpected results when filtered to a single product.
Solution: Understand that filters cascade. If you filter by “Widget A only”, YTD respects that filter.
Pitfall 3: SAMEPERIODLASTYEAR vs DATEADD
Problem: Not sure which to use.
Solution:
- Use SAMEPERIODLASTYEAR for exact 1-year offset
- Use DATEADD when you need flexibility (multiple years, quarters, months, days)
Summary
Function Quick Reference
| Function | Best For | Example |
| TOTALYTD | Cumulative yearly totals | Show YTD revenue through current month |
| SAMEPERIODLASTYEAR | Simple YoY comparison | Compare March 2024 vs March 2023 |
| DATEADD | Flexible period shifts | Compare Q1 2024 vs Q4 2023 |
Questions about other DAX topics? Let me know in the comment box!
