πWhat Is Time Intelligence?
Time intelligence means comparing numbers across periods: year to date, last year, growth, rolling totals and moving averages. It is the most requested DAX skill in Power BI jobs and interviews, because every business report compares "now" with "before".
DAX has dedicated time intelligence functions, but they only work correctly with a proper date table. If DAX is new to you, start with the DAX functions cheat sheet.
πStep 1: Build the Date Table
Requirements:
Date =VAR MinYear = YEAR ( MIN ( Sales[OrderDate] ) )VAR MaxYear = YEAR ( MAX ( Sales[OrderDate] ) )RETURNADDCOLUMNS ( CALENDAR ( DATE ( MinYear, 1, 1 ), DATE ( MaxYear, 12, 31 ) ), "Year", YEAR ( [Date] ), "Quarter", "Q" & QUARTER ( [Date] ), "Month", FORMAT ( [Date], "MMM" ), "MonthNo", MONTH ( [Date] ), "YearMonth", FORMAT ( [Date], "YYYY MM" ), "FY", "FY" & IF ( MONTH ( [Date] ) >= 4, YEAR ( [Date] ) + 1, YEAR ( [Date] ) ), "FY MonthNo", MOD ( MONTH ( [Date] ) + 8, 12 ) + 1, "Weekday", FORMAT ( [Date], "ddd" ), "WeekdayNo", WEEKDAY ( [Date], 2 ))Sort Month by MonthNo and Weekday by WeekdayNo. The FY columns implement the April to March financial year used by most Indian companies. You can also build the date table in Power Query or SQL.
πStep 2: Base Measure
Total Sales = SUM ( Sales[SalesAmount] )All time intelligence measures reference this.
πYear, Quarter and Month to Date
Sales YTD = TOTALYTD ( [Total Sales], 'Date'[Date] )Sales QTD = TOTALQTD ( [Total Sales], 'Date'[Date] )Sales MTD = TOTALMTD ( [Total Sales], 'Date'[Date] )Sales FYTD = TOTALYTD ( [Total Sales], 'Date'[Date], "31/03" )The equivalent with CALCULATE, useful to understand what happens:
Sales YTD v2 = CALCULATE ( [Total Sales], DATESYTD ( 'Date'[Date] ) )πLast Year and Growth
Sales LY = CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )Sales YoY = [Total Sales] - [Sales LY]Sales YoY % = DIVIDE ( [Sales YoY], [Sales LY] )Sales YTD LY = CALCULATE ( [Sales YTD], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )DATEADD is the flexible version:
Sales LM = CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, MONTH ) )Sales LQ = CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, QUARTER ) )Sales MoM % = DIVIDE ( [Total Sales] - [Sales LM], [Sales LM] )PARALLELPERIOD and PREVIOUSYEAR / PREVIOUSMONTH return whole periods, for example the full previous year regardless of the selected months.
πRolling Totals and Moving Averages
Sales Rolling 12M =CALCULATE ( [Total Sales], DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -12, MONTH ))Sales 3M Moving Avg =AVERAGEX ( DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, MONTH ), [Total Sales])The moving average above averages days. For a true average of monthly totals, iterate months:
Sales 3M Avg (monthly) =VAR Months = CALCULATETABLE ( VALUES ( 'Date'[YearMonth] ), DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, MONTH ) )RETURN AVERAGEX ( Months, [Total Sales] )πRunning Total (All Time)
Sales Running Total =CALCULATE ( [Total Sales], FILTER ( ALL ( 'Date'[Date] ), 'Date'[Date] <= MAX ( 'Date'[Date] ) ))Use ALLSELECTED instead of ALL if the running total should restart within the selected range.
πHandling Partial Periods
A classic bug: the current month is half finished, so YoY looks terrible. Options:
Last Sales Date = CALCULATE ( MAX ( Sales[OrderDate] ), ALL ( Sales ) )Sales LY Same Days =VAR LastDate = [Last Sales Date]RETURNCALCULATE ( [Sales LY], KEEPFILTERS ( 'Date'[Date] <= EDATE ( LastDate, 0 ) ))Or add a column IsPastDate to the date table (Date <= last sales date) and filter visuals or measures with it so future dates never show.
πWeek Based Calculations
Standard functions assume calendar months. For retail 4-4-5 calendars or ISO weeks, add Week and WeekYear columns to the date table and write CALCULATE with filters on those columns, for example previous week by WeekIndex minus one. Newer Power BI versions are adding calendar based time intelligence to make custom calendars easier; check current documentation.
πSemi Additive Measures: Balances and Inventory
Balances should not be summed over time. Use the closing value:
Closing Stock =CALCULATE ( SUM ( Inventory[Qty] ), LASTNONBLANK ( 'Date'[Date], CALCULATE ( SUM ( Inventory[Qty] ) ) ) )Closing Balance Month = CLOSINGBALANCEMONTH ( SUM ( Accounts[Balance] ), 'Date'[Date] )πCalculation Groups for Time Intelligence
Instead of writing YTD, LY and YoY for every base measure, create a calculation group (in Tabular Editor or the model view) with items like:
YTD = CALCULATE ( SELECTEDMEASURE (), DATESYTD ( 'Date'[Date] ) )LY = CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( 'Date'[Date] ) )YoY% = VAR Cur = SELECTEDMEASURE () VAR Prev = CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( 'Date'[Date] ) ) RETURN DIVIDE ( Cur - Prev, Prev )One group now works with Sales, Profit, Orders and every other measure.
πCommon Time Intelligence Mistakes
πFrequently Asked Questions
Why does SAMEPERIODLASTYEAR return blank?
Usually because there is no proper date table, it is not related to the fact, or the previous year has no data.What is the difference between DATEADD and SAMEPERIODLASTYEAR?
SAMEPERIODLASTYEAR shifts back exactly one year. DATEADD shifts by any number of days, months, quarters or years.How do I calculate fiscal year YTD in Power BI?
Use TOTALYTD with a year end date argument, for example "31/03" for an April to March year.Is time intelligence asked in interviews?
Constantly. Practise with Power BI interview questions and scenario based questions.πLearn It Live
Prakalpana's Power BI course drills time intelligence on real finance and sales models, taught live online with an optional 1-on-1 track. See the Power BI learning path, then WhatsApp or call +91 9180377502 for a free demo.