Skip to content
ALLURE
Skip to main content

Allure Analytics

Time Intelligence in Power BI

Time Intelligence Power Bi Cover

Time intelligence evaluates a measure over a defined date window: year-to-date, quarter-to-date, month-to-date, a rolling period or a comparable earlier period. Begin with a suitable shared Date table, create a reusable base measure such as Sales Actuals = SUM(Sales[SalesAmount]), and then apply the required date filter to that measure. This article retains the original classic date-column DAX examples and their order. article about creating Calendar (Date) table in Power BI. Create a date table.

Sales Actuals = SUM(Sales[SalesAmount])

Time-period timeline

Time Intelligence Timeline


Aggregations


Year-to-date (YTD) runs from the start of the calendar year—or the configured fiscal year—to the last date in the current reporting context.

Year-to-date values in the original example.
Year-to-date values in the original example.
YTD = CALCULATE([Sales Actuals], DATESYTD('Date'[Date])) -- Option 1
YTD = TOTALYTD([Sales Actuals], 'Date'[Date]) -- Option 2 (sugar syntax)

DirectQuery clarification: the archived article described a blanket restriction. The documented DATESYTD restriction concerns calculated columns and row-level-security rules in DirectQuery; it is not a general prohibition on using the function in measures. Check the supported use for your model. DATESYTD supported usage.

The original custom YTD alternative filters the calendar explicitly.

Original typographic quotes are retained. “Copy straight quotes” changes only those quote characters when pasting into an editor that requires standard DAX quotation marks.

YTD (custom) = 
CALCULATE([Sales Actuals],
  FILTER(
     ALL('Date’),
  'Date'[Year] = MAX('Date'[Year])
  &&
  'Date'[Date] <= MAX('Date'[Date])))

The first custom expression uses the Year attribute. The next derives the year from the Date column. Retain the intended year and cutoff-date context when comparing these alternatives.

YTD (custom) v2 =
CALCULATE (
    [Sales Actuals],
    FILTER (
        ALL ('Date'[Date]),
        
'Date'[Date] <= MAX ('Date'[Date])
  &&
YEAR ('Date'[Date]) = YEAR ( MAX ('Date'[Date]))))

Quarter-to-date (QTD)

QTD covers the start of the selected quarter through the last date in the current context.

Quarter-to-date values in the original example.
Quarter-to-date values in the original example.
Calendar YTD and QTD compared.
Calendar YTD and QTD compared.
QTD = 
CALCULATE(
  [Sales Actuals], 
  DATESQTD('Date'[Date])) -- Option 1
QTD = TOTALQTD([Sales Actuals],'Date'[Date]) -- Option 2 (sugar syntax)

For DirectQuery, review the function’s supported usage rather than assuming that all QTD measures are unavailable. The custom source expression below is an alternative filter pattern, not a universal DirectQuery workaround.

The custom QTD expression uses the calendar’s Year and Quarter attributes. If the model uses a different calendar structure, adapt the period boundaries deliberately.

Original typographic quotes are retained. “Copy straight quotes” changes only those quote characters when pasting into an editor that requires standard DAX quotation marks.

QTD (custom) = 
CALCULATE (
[Sales Actuals],
  FILTER (
  ALL ( 'Date’),
  'Date'[Year] = MAX ('Date'[Year]) 
  &&
  'Date'[Quarter] = MAX ('Date'[Quarter]) 
  &&
  'Date'[Date] <= MAX ('Date'[Date])))

Month-to-date (MTD)

MTD covers the start of the selected month through the last date in the current context. Excluding an incomplete current day is a separate business rule; the functions below do not exclude today automatically.

Month-to-date values in the original example.
Month-to-date values in the original example.
MTD = 
CALCULATE(
[Sales Actuals], 
DATESMTD('Date'[Date])) -- Option 1
MTD = TOTALMTD([Sales Actuals],'Date'[Date]) -- Option 2 (sugar syntax)

Validate DirectQuery support and the date-table design for the particular function. The explicit calendar-filter alternative below preserves the source example.

MTD (custom) = 
CALCULATE(
[Sales Actuals],
  FILTER(
  ALL('Date'),
'Date'[Year] = MAX ('Date'[Year]) 
&&
'Date'[Month] = MAX ('Date'[Month]) 
&&
'Date'[Date] <= MAX ('Date'[Date])))

Fiscal year-to-date (FYTD)

Classic DAX YTD functions can use an optional year-end date. The default is 31 December; specifying another year end changes the fiscal accumulation window.

For a year beginning on 1 June, a reporting date of 15 June produces calendar YTD from 1 January to 15 June and fiscal YTD from 1 June to 15 June. The opening timeline shows the relationship between these windows.

FYTD = CALCULATE([Sales Actuals], DATESYTD('Date'[Date], "05/31")) -- Option 1
FYTD = 
TOTALYTD([Sales Actuals],
'Date'[Date], 
ALL('Date'[Date]),"05/31") -- Option 2

For the illustrated June-start fiscal year, the year-end argument is “05/31”. The date-string interpretation depends on the model’s locale.

The fiscal year-to-date chart.
The fiscal year-to-date chart.
Calendar YTD and fiscal YTD compared.
Calendar YTD and fiscal YTD compared.

The two visuals contrast calendar-year and fiscal-year accumulation.


Running total or cumulative sum

A cumulative total over the illustrated reporting dates.
A cumulative total over the illustrated reporting dates.

A running total accumulates successive values up to the current point in an ordered sequence. On a date axis, it shows how the measure has built up over time.

Sales Running Total = 
IF(
[Sales Actuals] <> BLANK(),
CALCULATE(
[Sales Actuals],
FILTER(
ALL('Date'[Date]),
'Date'[Date] <= MAX('Date'[Date]))))

Power BI quick measures can generate a related running-total expression. The retained example uses ALLSELECTED, so its selection scope should be checked against the ALL-based expression above.

Sales RT Quick Measure = 
CALCULATE(
    [Sales Actuals],
    FILTER(
        ALLSELECTED('Date'[Date]),
        ISONORAFTER('Date'[Date], MAX('Date'[Date]), DESC)
    )
)
The running-total result in a table.
The running-total result in a table.

A running total can also follow ordered identifiers, such as product keys. A financial statement can use the same general idea with a deliberate account ordering and subtotal design. The next source example accumulates by ProductKey.

Sales RT by Category = 
-- In this case we calculate running total by products
VAR CategoryMax = MAX ( dimProduct[ProductKey] ) --or SELECTEDVALUE(dimProduct[ProductKey])
RETURN
    CALCULATE (
        [Sales Actuals],
        FILTER(
            ALL ( dimProduct),
        dimProduct[ProductKey] <= CategoryMax
        
    ))
The source running total follows ProductKey order.
The source running total follows ProductKey order.

Moving annual total (MAT)

The moving annual total over a rolling twelve-month window.
The moving annual total over a rolling twelve-month window.

A MAT reports a rolling twelve-month total. Its endpoint follows the current reporting context, so the result can be viewed by day, month or quarter. Rolling annual values can smooth seasonal variation and help reveal an underlying trend; they do not remove every source of seasonality or constitute a forecast by themselves.

Last N Months = 
VAR Months = 12 -- change this number by your needs
RETURN
CALCULATE (
[Sales Actuals],
DATESINPERIOD (
'Date'[Date], -- returns period from date column
MAX ('Date'[Date]), -- starting from MAX date
-Months, -- shifting it back n intervals
MONTH -- each interval being a month
))

The source also expresses the rolling window using a one-year interval. Compare the resulting boundaries for the calendar and reporting context in use.

Last N Months v2 = 
VAR Years = 1 -- change this number by your needs
RETURN
CALCULATE (
[Sales Actuals],
DATESINPERIOD (
'Date'[Date], -- returns period from date
column
MAX ('Date'[Date]), -- starting from MAX date
- Years, -- shifting it back n intervals
YEAR -- each interval being a year
))

A quarterly rolling window uses the same pattern with QUARTER as the interval. The retained example sets the number of quarters to 1.

Last N Quarters = 
VAR Quarters = 1 -- change this number by your needs
RETURN
CALCULATE (
[Sales Actuals],
DATESINPERIOD (
'Date'[Date], -- returns period from date
column
MAX ('Date'[Date]), -- starting from MAX date
- Quarters, -- shifting it back n intervals
QUARTER -- each interval being a quarter
))

Shift the reporting period


Sales in the previous year, quarter or month

Sales LY = CALCULATE(
  [Sales Actuals], 
  DATEADD('Date'[Date], -1,YEAR)) --Option 1
Sales LY = CALCULATE([Sales Actuals],
SAMEPERIODLASTYEAR('Date'[Date])) -- Option 2

Check the function’s DirectQuery remarks and model requirements. The next custom source expression selects the entire previous year from the calendar, which is not the same operation as shifting an arbitrary selected date range.

Sales LY (custom) = 
CALCULATE(
[Sales Actuals],
FILTER (
ALL ('Date'),
'Date'[Year] = MAX ('Date'[Year])-1))

The quarter and month alternatives below illustrate two concepts: DATEADD shifts the selected dates, while PREVIOUSQUARTER and PREVIOUSMONTH return the preceding complete period. Do not assume that they are interchangeable for every selection. PREVIOUSQUARTER period semantics.

Sales LQ = CALCULATE(
  [Sales Actuals], 
  DATEADD('Date'[Date], -1,QUARTER))
Sales LQ = CALCULATE([Sales Actuals], 
PREVIOUSQUARTER('Date'[Date])) -- Option 2
Sales LM = CALCULATE(
  [Sales Actuals], 
  DATEADD('Date'[Date], -1,MONTH))
Sales LM = CALCULATE([Sales Actuals], 
PREVIOUSMONTH('Date'[Date])) -- Option 2

Apply the period shift to a YTD, QTD or MTD measure to compare accumulated results. Keep the intended comparison clear: previous quarter, previous month and the same period last year are different windows.

Sales LYTD = CALCULATE(
  [YTD], 
  DATEADD('Date'[Date], -1,YEAR)) --Option 1
Sales LYTD = CALCULATE([YTD], SAMEPERIODLASTYEAR('Date'[Date])) --Option 2
Sales LYTD = TOTALYTD([Sales Actuals], 
SAMEPERIODLASTYEAR('Date'[Date])) --Option 3
Sales LQTD = CALCULATE(
  [QTD], 
  DATEADD('Date'[Date], -1,QUARTER)) --Option 1

Source clarification: this expression shifts QTD or MTD back one year. It is retained as originally written; it is not the previous-quarter or previous-month-to-date variant.

Sales LQTD = CALCULATE([QTD], SAMEPERIODLASTYEAR('Date'[Date])) --Option 2
Sales LMTD = CALCULATE(
  [MTD], 
  DATEADD('Date'[Date], -1,MONTH)) --Option 1

Source clarification: this expression shifts QTD or MTD back one year. It is retained as originally written; it is not the previous-quarter or previous-month-to-date variant.

Sales LMTD = CALCULATE([MTD], SAMEPERIODLASTYEAR('Date'[Date])) --Option 2

Compare periods


Current year versus last year

Year-over-year comparison evaluates the current result against the equivalent prior-year period. Use an absolute difference for the change in units or currency and a ratio for the percentage change.

YoY Variance = [Sales Actuals] - [Sales LY]

Decide how missing and zero values should affect the comparison. A missing prior-year value should not automatically be interpreted as zero sales and reported as growth. The following source variants suppress results when one or both comparison values are missing or when the business rule excludes zero values.

YoY Variance (ignore blanks) =
IF(
NOT ISBLANK ([Sales Actuals])
&& 
NOT ISBLANK ([Sales LY]),
[Sales Actuals] - [Sales LY])
YoY Variance (ignore 0) = 
IF (
[Sales Actuals] <> 0
&& [Sales LY] <> 0,
[Sales Actuals] - [Sales LY],
BLANK()
)

Calculate percentage change as (current − previous) / previous. DIVIDE handles a zero or BLANK denominator using its alternate-result behaviour. The Best Practices article explains the distinction between DIVIDE and the division operator. Best Practices in Power BI.

YoY % = DIVIDE([YoY Variance], [Sales LY])

Use consistent time-measure names

The original time-intelligence naming-conventions reference; source credit: SQLBI.
The original time-intelligence naming-conventions reference; source credit: SQLBI.

Open the original naming-conventions image