DAX Time Intelligence: YTD, Same Period Last Year and the Date Table You Need First

Gulab Chand Tejwani
PMP · PL-300 · Microsoft Certified Trainer
· 11 min read

DAX time intelligence functions such as TOTALYTD, SAMEPERIODLASTYEAR, DATEADD and DATESINPERIOD let you compare sales across periods: year to date, the same period last year, last month, or a rolling twelve months. They only work reliably on top of a proper date table: one row per day, no gaps, covering whole years, related to your fact table and marked as a date table in Power BI. Build the date table first, then the measures are short.
I'm Gulab Chand Tejwani, a Microsoft Certified Trainer and PL-300 certified Power BI analyst at TechNet Consultancy in Anand. "Year to date" is the first thing every manager asks for, and broken year-to-date numbers are the most common Power BI bug I'm asked to fix. Almost every time, the measure is fine and the date table is the problem. So we'll start there.
Why do you need a separate date table?
Your sales table has an InvoiceDate column, so why not use that? Because it only contains dates when something happened. If nothing sold on a Sunday, that date doesn't exist in the data. Time intelligence functions shift and compare whole ranges of dates, and they need every date to be there.
Power BI does create hidden automatic date tables for each date column if the "Auto date/time" option is on. They're fine for a quick look, but you can't add a financial year, they bloat the model with one hidden table per date column, and they don't help when you have several fact tables. Microsoft's own guidance on auto date/time recommends turning it off for serious models. I switch it off in File, then Options and settings, then Options, under Data Load, for both the current file and globally.

Microsoft also lists the requirements for a date table in Set and use date tables in Power BI Desktop: a date column with unique values, no blanks, and contiguous dates. In practice, cover whole years from the first to the last year in your data.
How do you create a date table in DAX?
Go to Modeling, then New table, and paste this. It covers April 2023 to March 2027 and adds Indian financial year columns, with the year starting on 1 April:
Date =
ADDCOLUMNS (
CALENDAR ( DATE ( 2023, 4, 1 ), DATE ( 2027, 3, 31 ) ),
"Year", YEAR ( [Date] ),
"Month Number", MONTH ( [Date] ),
"Month", FORMAT ( [Date], "MMM" ),
"Year Month", FORMAT ( [Date], "YYYY-MM" ),
"Quarter", "Q" & QUARTER ( [Date] ),
"FY Month Number", MOD ( MONTH ( [Date] ) - 4, 12 ) + 1,
"Financial Year",
VAR StartYear = IF ( MONTH ( [Date] ) >= 4, YEAR ( [Date] ), YEAR ( [Date] ) - 1 )
RETURN "FY " & StartYear & "-" & RIGHT ( StartYear + 1, 2 )
)
Change the two dates to match your data. CALENDAR returns one row per day between them. CALENDARAUTO can work out the range for you, but I prefer explicit dates so I know exactly what's in the model.

Then do four things:
- Mark it as a date table. Select the table, choose Mark as date table, and pick the Date column. Power BI checks that the dates are unique and contiguous.
- Sort the text columns. Select Month and set Sort by column to Month Number, otherwise April sorts before January. For a financial-year view, sort by FY Month Number instead, so April comes first.
- Create the relationship. Date[Date] to Sales[InvoiceDate], one-to-many, single direction. If your fact table has a datetime column with times, remove the time in Power Query first, or the dates won't match.
- Use the Date table in visuals. Put Date[Month] on the axis, never Sales[InvoiceDate]. If you use the fact table's date column, time intelligence breaks in confusing ways.
You can also build the same table in Power Query if your team prefers M. Microsoft's date table guidance compares the options. Where the date table sits in the model is covered in star schema in Power BI for beginners.
How do you calculate year to date in DAX?
Start with a base measure:
Total Sales = SUM ( Sales[Amount] )
Calendar year to date:
Sales YTD = TOTALYTD ( [Total Sales], 'Date'[Date] )
For an Indian financial year ending 31 March, pass a year-end date as the third argument:
Sales FYTD = TOTALYTD ( [Total Sales], 'Date'[Date], "3/31" )
The year-end string is read using the locale of the model, so if "3/31" gives odd results in your setup, check your locale settings. The TOTALYTD reference explains the argument. TOTALYTD is shorthand for CALCULATE with DATESYTD, so this is equivalent:
Sales FYTD (Explicit) =
CALCULATE ( [Total Sales], DATESYTD ( 'Date'[Date], "3/31" ) )
I teach the CALCULATE form, because once you understand it you can combine it with other filters. If CALCULATE still feels slippery, read DAX CALCULATE explained with examples first.
How do you compare with the same period last year?
Sales LY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
SAMEPERIODLASTYEAR takes whatever dates are currently in context (a month, a quarter, a single day) and shifts them back one year. In a matrix by month, each month compares with the same month last year.
Growth is then simple:
Sales YoY % =
DIVIDE ( [Total Sales] - [Sales LY], [Sales LY] )
DIVIDE returns blank instead of an error when last year is zero. And last year's year-to-date, for comparing "where were we at this point last year":
Sales FYTD LY =
CALCULATE ( [Sales FYTD], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
Plot Sales FYTD and Sales FYTD LY on a line chart by financial-year month and you get the view most sales heads want on the first page of their report.

Previous month and rolling 12 months
For month-on-month comparisons, DATEADD shifts by any interval:
Sales PM =
CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, MONTH ) )
A rolling 12 months smooths out seasonality, which is useful for businesses with festival peaks like Diwali:
Sales Rolling 12M =
CALCULATE (
[Total Sales],
DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -12, MONTH )
)
MAX('Date'[Date]) gives the last date in the current context, and DATESINPERIOD returns the 12 months ending there.
Which time intelligence function should you use?
| Function | Returns | Typical measure |
|---|---|---|
| TOTALYTD / DATESYTD | Dates from year start to the current date | Year to date, financial year to date |
| SAMEPERIODLASTYEAR | Current dates shifted back one year | Last year, YoY growth |
| DATEADD | Current dates shifted by any interval | Previous month, previous quarter |
| DATESINPERIOD | A window of dates ending on a given date | Rolling 3 or 12 months |
| PARALLELPERIOD | The full period shifted by an interval | Full last-year total on every month |
| LASTNONBLANK | The last date that has a value | Closing stock or balance |
The difference between DATEADD and PARALLELPERIOD trips people up. DATEADD shifts exactly the dates in context, so in March it returns last March. PARALLELPERIOD returns the whole period, so PARALLELPERIOD('Date'[Date], -1, YEAR) in March returns all of last calendar year.
How do you handle stock and balances?
Sales add up over time. Stock levels and bank balances don't: you can't add 31 daily closing balances and call it the month's balance. These are called semi-additive measures, and they're named in the PL-300 outline.
The usual pattern takes the value on the last date in the period that actually has data:
Closing Stock =
CALCULATE (
SUM ( Inventory[Units] ),
LASTNONBLANK ( 'Date'[Date], CALCULATE ( SUM ( Inventory[Units] ) ) )
)
In a matrix by month, each month shows the stock on its last recorded date, and the year total shows the stock on the last recorded date of the year. That's what a stores manager expects.
Why are my time intelligence numbers wrong?
The fixes I make most often:
- YTD shows the same value in every month. The visual uses Sales[InvoiceDate] instead of Date[Month], or the relationship is missing.
- Last year is blank. The date table doesn't go back far enough. Extend the CALENDAR range.
- YTD keeps going into future months. The date table runs to March 2027, so future months show the full-year total. Hide them with the measure below.
- Totals look wrong in the financial year. You forgot the "3/31" year-end, so YTD resets in January.
- Dates have times. A datetime column won't match the date-only key. Change the type to Date in Power Query.
- The date table isn't marked. Mark it, especially if the relationship uses a column that isn't a pure date type.
This version of FYTD stops at the last date with sales, so future months stay blank:
Sales FYTD (To Date) =
VAR LastSaleDate =
CALCULATE ( MAX ( Sales[InvoiceDate] ), REMOVEFILTERS ( 'Date' ) )
RETURN
IF ( MIN ( 'Date'[Date] ) <= LastSaleDate, [Sales FYTD] )
How does time intelligence appear on PL-300?
The PL-300 skills outline lists "Create a common date table" under designing the model and "Implement time intelligence measures" and "Create semi-additive measures" under DAX calculations. Expect scenario questions about which function returns year-to-date or last year's figure, and about why a measure returns the wrong result. The PL-300 exam guide has the whole outline.
Practise it on your own data
Take any sales file with at least two years of dates, build the date table above, and create the measures in this post: Sales, FYTD, LY, YoY %, PM and Rolling 12M. Put them in a matrix by Financial Year and Month. When every number reconciles with a manual check in Excel, you've got it. If your data still needs cleaning first, start with the Power Query data cleaning steps.
In our Power BI training in Anand and live online, time intelligence is part of the 10-hour data modelling and DAX module, and we build exactly this financial-year setup because Indian businesses report April to March. If you'd rather learn on your own, the self-paced Power BI online course includes DAX lessons and labs, with a free preview lesson to try first.
FAQ
What is time intelligence in Power BI?
Time intelligence is a group of DAX functions that calculate values over periods, such as year to date, the same period last year, or a rolling twelve months, by shifting or extending the dates in the current filter context.
Do I need a date table for time intelligence?
Yes, in practice. Time intelligence functions need a continuous range of dates with no gaps. A dedicated date table, related to your fact table and marked as a date table, is the reliable way to provide one.
How do I calculate financial year to date for India?
Use TOTALYTD or DATESYTD with a year-end date of 31 March, for example TOTALYTD([Total Sales], 'Date'[Date], "3/31"). Add Financial Year and FY Month Number columns to your date table for grouping and sorting.
What is the difference between SAMEPERIODLASTYEAR and DATEADD?
SAMEPERIODLASTYEAR always shifts back exactly one year. DATEADD can shift by any number of days, months, quarters or years, forward or back. DATEADD('Date'[Date], -1, YEAR) behaves like SAMEPERIODLASTYEAR.
Should I turn off Auto date/time in Power BI?
For models you'll maintain or share, yes. Use your own date table instead. Auto date/time creates a hidden table for every date column and doesn't support a financial year.