Sub topic 1
Start with a Proper Date Table
Prerequisites
Assume you know basic DAX measures such as SUM and DIVIDE, understand fact and dimension tables in a star schema, and can place a measure in a Power BI visual.
Start with a proper date table
A date table is a table with one row for every calendar date in the reporting range. It should contain no gaps. Relate 'Date'[Date] to the fact table's date column, such as Sales[Order Date]. Then mark it as the model's date table in Power BI.
Date =
ADDCOLUMNS (
CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2025, 12, 31 ) ),
"Year", YEAR ( [Date] ),
"Month Number", MONTH ( [Date] ),
"Year Month", FORMAT ( [Date], "yyyy-MM" )
)Sort month names by Month Number, and use columns from the date table in visuals. A complete date table lets DAX navigate periods even when the fact table has no sales on a particular day.
Filter context and dates
Filter context is the set of filters active when a measure runs. A matrix row for 2024 and a slicer for March create a context containing dates in March 2024. The same measure can therefore return different values in different visual cells.
CALCULATE changes the dates a measure sees
CALCULATE evaluates a measure after modifying its filter context. A date function supplies a new set of dates, and CALCULATE evaluates the measure for those dates.
Total Sales = SUM ( Sales[Sales Amount] )
Sales YTD =
CALCULATE (
[Total Sales],
DATESYTD ( 'Date'[Date] )
)If the visual is on March 15, DATESYTD returns dates from January 1 through March 15. CALCULATE replaces the current date filter with that set, while other filters, such as product or region, usually remain active.
What time intelligence functions actually return
Time intelligence functions generally return a table of dates. They do not calculate sales by themselves. DATESYTD returns dates from the year's start through the current date. SAMEPERIODLASTYEAR returns the corresponding dates one year earlier. DATESINPERIOD returns a specified rolling window.
TOTALYTD is a shortcut for the CALCULATE and DATESYTD pattern:
Sales YTD (Shortcut) =
TOTALYTD ( [Total Sales], 'Date'[Date] )Exercise
Why can a date table with gaps produce incorrect time-intelligence results?
Show answer
Time-intelligence functions need every date in the requested period to shift and accumulate dates consistently.