DAX time intelligence functions: every one with an example

A reference of all DAX time intelligence functions, period to date (TOTALYTD, DATESYTD and more), shifts (SAMEPERIODLASTYEAR, DATEADD, PARALLELPERIOD, PREVIOUS and NEXT), ranges (DATESBETWEEN, DATESINPERIOD), period boundaries, and opening and closing balances, with examples.

Short answer: DAX time intelligence functions return sets of dates to use as filters in CALCULATE (DATESYTD, SAMEPERIODLASTYEAR, DATEADD, DATESINPERIOD), or values at a point in time (TOTALYTD, CLOSINGBALANCEMONTH). They take the date column of a date table, or with calendar-based time intelligence a calendar, which also enables the week functions.

This page lists every function in the group, with one example each, in the order you are likely to need them.

Which functions total to date?

FunctionReturnsExample
TOTALYTDthe expression from the start of the yearTOTALYTD ( [Revenue], 'Date'[Date] )
TOTALQTDfrom the start of the quarterTOTALQTD ( [Revenue], 'Date'[Date] )
TOTALMTDfrom the start of the monthTOTALMTD ( [Revenue], 'Date'[Date] )
TOTALWTDfrom the start of the week (calendar only)TOTALWTD ( [Revenue], 'Retail 445' )
DATESYTDthe dates from the start of the yearCALCULATE ( [Revenue], DATESYTD ( 'Date'[Date], "6-30" ) )
DATESQTDthe dates from the start of the quarterCALCULATE ( [Revenue], DATESQTD ( 'Date'[Date] ) )
DATESMTDthe dates from the start of the monthCALCULATE ( [Revenue], DATESMTD ( 'Date'[Date] ) )
DATESWTDthe dates from the start of the week (calendar only)CALCULATE ( [Revenue], DATESWTD ( 'Retail 445' ) )
Period to date

In depth: YTD, QTD and MTD.

Which functions shift periods?

FunctionReturnsExample
SAMEPERIODLASTYEARthe same dates one year backCALCULATE ( [Revenue], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
DATEADDthe dates shifted by n intervalsCALCULATE ( [Revenue], DATEADD ( 'Date'[Date], -1, MONTH ) )
PARALLELPERIODthe whole period n intervals awayCALCULATE ( [Revenue], PARALLELPERIOD ( 'Date'[Date], -1, YEAR ) )
PREVIOUSDAYthe day before the first date in contextCALCULATE ( [Revenue], PREVIOUSDAY ( 'Date'[Date] ) )
PREVIOUSWEEKthe previous week (calendar only)CALCULATE ( [Revenue], PREVIOUSWEEK ( 'Retail 445' ) )
PREVIOUSMONTHall dates of the previous monthCALCULATE ( [Revenue], PREVIOUSMONTH ( 'Date'[Date] ) )
PREVIOUSQUARTERall dates of the previous quarterCALCULATE ( [Revenue], PREVIOUSQUARTER ( 'Date'[Date] ) )
PREVIOUSYEARall dates of the previous yearCALCULATE ( [Revenue], PREVIOUSYEAR ( 'Date'[Date] ) )
NEXTDAY, NEXTWEEK, NEXTMONTH, NEXTQUARTER, NEXTYEARthe following periodCALCULATE ( [Forecast], NEXTMONTH ( 'Date'[Date] ) )
Shifts

In depth: year over year.

Which functions return a range?

FunctionReturnsExample
DATESBETWEENthe dates from a start to an end dateCALCULATE ( [Revenue], DATESBETWEEN ( 'Date'[Date], DATE ( 2026, 1, 1 ), DATE ( 2026, 3, 31 ) ) )
DATESINPERIODthe dates from a start, n intervals back or forwardCALCULATE ( [Revenue], DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -12, MONTH ) )
Ranges

In depth: rolling 12 months.

Which functions find period boundaries?

FunctionReturnsExample
FIRSTDATEthe first date in contextFIRSTDATE ( 'Date'[Date] )
LASTDATEthe last date in contextCALCULATE ( [Units], LASTDATE ( 'Date'[Date] ) )
STARTOFMONTH, STARTOFQUARTER, STARTOFYEAR, STARTOFWEEKthe first date of the period in contextSTARTOFMONTH ( 'Date'[Date] )
ENDOFMONTH, ENDOFQUARTER, ENDOFYEAR, ENDOFWEEKthe last date of the period in contextENDOFYEAR ( 'Date'[Date], "6-30" )
First, last, start and end

FIRSTDATE and LASTDATE return a one-row table, so they work as filters in CALCULATE; MIN and MAX return a value. The week versions need a calendar.

Which functions return balances?

FunctionReturnsExample
CLOSINGBALANCEMONTH, CLOSINGBALANCEQUARTER, CLOSINGBALANCEYEAR, CLOSINGBALANCEWEEKthe expression at the last date of the periodCLOSINGBALANCEMONTH ( SUM ( Stock[Units] ), 'Date'[Date] )
OPENINGBALANCEMONTH, OPENINGBALANCEQUARTER, OPENINGBALANCEYEAR, OPENINGBALANCEWEEKthe expression at the end of the previous periodOPENINGBALANCEYEAR ( SUM ( Stock[Units] ), 'Date'[Date] )
Opening and closing balances

In depth: opening and closing balances. FIRSTNONBLANK and LASTNONBLANK, which find the first or last date with data, are in the filter group but belong with these.

What goes wrong?

  • A fact table date column as input. Use the date table's column or a calendar.
  • Gaps in the date column. Classic functions throw an error on missing dates; calendars allow them.
  • Week functions with a date column. They need a calendar with a week category.
  • Nesting with calendars. PREVIOUSDAY ( PREVIOUSMONTH ( 'Calendar' ) ) is not supported; use CALCULATETABLE.

Where can you check this?

Where do you start?

Learn DATESYTD, SAMEPERIODLASTYEAR, DATEADD and DATESINPERIOD; with CALCULATE they cover nearly all time comparisons. Date and time functions covers building and splitting dates.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.