Skip to content

DAX Time Intelligence and Calculation Groups

Step 11 of 24

PL-300 DAX Time Intelligence: Rolling Totals, Closing Balances, and Calculation Groups

Build DAX measures for periods and snapshots

Sales can be added across days. Stock levels usually need the latest valid snapshot, and a monthly average must average months. DAX time intelligence starts by choosing what the dates and the total should mean.

This lesson covers time intelligence, semi-additive measures, and calculation groups in the PL-300 Model the data domain (25–30% of the exam, skills measured from April 20, 2026). Review DAX measures and CALCULATE filter context before applying those patterns to period filters.

Learning objectives

  • Explain what a date table must contain for time intelligence functions to work.
  • Write measures with TOTALYTD, DATESYTD, SAMEPERIODLASTYEAR, DATEADD, PARALLELPERIOD, DATESINPERIOD and DATESBETWEEN.
  • Calculate year-over-year growth and rolling averages.
  • Explain why balances and stock levels are semi-additive and write measures with CLOSINGBALANCEMONTH, LASTDATE, LASTNONBLANK and CALCULATE.
  • Create a calculation group with calculation items using SELECTEDMEASURE() and use SELECTEDMEASUREFORMATSTRING() for formats.
  • Identify the limits of calculation groups (explicit measures only, precedence, interaction with implicit measures).

1. Prerequisites: a proper date table

The examples use classic time intelligence with a date column. Build a dedicated dimension with one unique, non-null row per day, a contiguous range, and the full calendar or fiscal years the report needs. For the day-level key, use matching date values in the facts. Mark the dimension as a date table and create active one-to-many relationships from the dimension to each fact’s primary date. See building a shared date table in Power BI.

Calendar-based time intelligence has separate requirements and configuration. The classic rules and formulas below refer to date-column syntax, not a calendar reference.

DAX
DimDate =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2022, 1, 1 ), DATE ( 2027, 12, 31 ) ),
    "Year", YEAR ( [Date] ),
    "Month Number", MONTH ( [Date] ),
    "Month", FORMAT ( [Date], "MMM" ),
    "Month Start", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 ),
    "Quarter", "Q" & QUARTER ( [Date] )
)

CALENDAR takes explicit start and end dates; CALENDARAUTO uses eligible model dates and returns full years. Check whether unrelated dates expand the range. Sort Month by Month Number using Sort by column so that months do not appear alphabetically.

Why not use the fact table's own date column? Because the fact table only has rows for days with transactions. A missing date breaks the contiguous range that functions such as SAMEPERIODLASTYEAR need, and prior-period comparisons return wrong or blank results.

Exam tip: if a time intelligence measure returns blank or odd results, check first: is there a date table, is it marked, is it contiguous, and does the visual use the date table's columns (not the fact table's date column) on the axis?

2. Time intelligence functions

Time intelligence functions fall into families. Date-set functions such as DATESYTD can supply filters to CALCULATE. Functions such as TOTALYTD and CLOSINGBALANCEMONTH evaluate an expression and return a scalar.

Family Examples Typical use
Period-to-date DATESYTD, DATESQTD, DATESMTD, TOTALYTD, TOTALQTD, TOTALMTD Year-to-date sales
Shift in time SAMEPERIODLASTYEAR, DATEADD, PARALLELPERIOD, PREVIOUSMONTH, NEXTDAY Prior year or prior month comparison
Date range DATESINPERIOD, DATESBETWEEN Rolling 3 months, custom range
First / last FIRSTDATE, LASTDATE, FIRSTNONBLANK, LASTNONBLANK, ENDOFMONTH Balances, openings and closings

Year-to-date

DAX
Sales YTD =
TOTALYTD ( [Total Sales], DimDate[Date] )

-- Equivalent, more flexible form
Sales YTD (CALCULATE) =
CALCULATE ( [Total Sales], DATESYTD ( DimDate[Date] ) )

With classic date-column syntax, TOTALYTD ( [Total Sales], DimDate[Date], "6/30" ) uses 30 June as the fiscal year-end in an en-US model. The year-end literal is locale-dependent. TOTALYTD also supports an optional filter argument. An explicit alternative is CALCULATE ( [Total Sales], DATESYTD ( DimDate[Date], "6/30" ) ).

DAX formula bar: Sales YTD = TOTALYTD ( [Total Sales], 'Date'[Date] )

Prior period and growth

DAX
Sales PY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( DimDate[Date] ) )

Sales YoY % =
VAR Current = [Total Sales]
VAR Previous = [Sales PY]
RETURN DIVIDE ( Current - Previous, Previous )

In classic syntax, SAMEPERIODLASTYEAR returns the corresponding prior-year date set. Leap days and end-of-month extension can affect individual dates. DATEADD is more general: DATEADD ( DimDate[Date], -1, MONTH ) shifts one month; the interval can be DAY, MONTH, QUARTER or YEAR.

DAX formula bar: Sales PY = CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )

DAX formula bar: Sales YoY % = DIVIDE ( [Total Sales] - [Sales PY], [Sales PY] )

Function Shifts Notes
SAMEPERIODLASTYEAR -1 year Equal to DATEADD ( …, -1, YEAR )
DATEADD Any number of intervals Works on a contiguous selection of dates
PARALLELPERIOD Whole periods Returns the entire shifted period, even if the current selection covers only part of it
PREVIOUSMONTH / PREVIOUSQUARTER / PREVIOUSYEAR One period back Whole previous period

With a contiguous 1–15 March selection, DATEADD by minus one month returns 1–15 February, while PARALLELPERIOD returns the entire previous month. Do not generalize the example to every month-end or to noncontiguous selections.

Rolling windows

DAX
Sales Rolling 3M =
CALCULATE (
    [Total Sales],
    DATESINPERIOD ( DimDate[Date], MAX ( DimDate[Date] ), -3, MONTH )
)

Avg Sales Last 12 Complete Months =
VAR PeriodEnd = EOMONTH ( MAX ( DimDate[Date] ), -1 )
VAR PeriodStart = EOMONTH ( PeriodEnd, -12 ) + 1
RETURN
    CALCULATE (
        AVERAGEX ( VALUES ( DimDate[Month Start] ), COALESCE ( [Total Sales], 0 ) ),
        FILTER ( ALL ( DimDate ), DimDate[Date] >= PeriodStart && DimDate[Date] <= PeriodEnd )
    )

The second measure excludes the month containing the latest visible date. It filters the date table to the preceding 12 complete months, then evaluates the measure once per month. COALESCE treats a month without sales as zero. Use it only if missing sales truly mean zero, and ensure the calendar covers the full window.

DAX formula bar: Sales Rolling 3M = CALCULATE ( [Total Sales], DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, MONTH ) )

DATESBETWEEN ( DimDate[Date], start, end ) returns a custom range, for example from the start of the year to the last day with data: DATESBETWEEN ( DimDate[Date], DATE ( 2026, 1, 1 ), MAX ( FactSales[OrderDate] ) ).

Worked example: year-over-year comparison

Scenario. Contoso Retail has FactSales (OrderDate, Amount) related to DimDate. The CFO wants a table visual with months on rows and three columns: sales, sales in the same month last year, and the percentage change. In January 2027 the visual should show blanks for the prior year if no 2026 data exists, not errors.

Step 1 – confirm the model. DimDate covers 2022–2027, is marked as a date table, and is related to FactSales[OrderDate].

Step 2 – base measure. Total Sales = SUM ( FactSales[Amount] ).

Step 3 – prior-year measure. Sales PY = CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( DimDate[Date] ) ). In the row for March 2027, DimDate[Date] is filtered to 1–31 March 2027; the function returns 1–31 March 2026, and CALCULATE replaces the date filter, so the measure returns March 2026 sales.

Step 4 – growth measure. Use DIVIDE so that an empty or zero prior year returns blank rather than a divide-by-zero error: Sales YoY % = DIVIDE ( [Total Sales] - [Sales PY], [Sales PY] ).

Step 5 – formatting. Format Sales YoY % as percentage in the Measure tools ribbon, and put the year and month from DimDate on rows, or use the month-start column formatted as year and month.

Matrix by year and month: Sales YTD accumulates through 2025 and restarts in January 2026; Sales PY for January 2026 equals January 2025; Sales YoY % is -13.18%

Why the alternatives are worse. Using FactSales[OrderDate] inside SAMEPERIODLASTYEAR fails because the fact column has gaps and is not the marked date column. The division operator can produce a nonfinite result for a zero or blank denominator. DIVIDE explicitly returns blank by default. Using PARALLELPERIOD would also work for full months but is overkill and returns the whole month when the visual is filtered to part of one.

3. Semi-additive measures

An additive measure (sales amount) can be summed across every dimension. A non-additive measure (a ratio) cannot be summed at all. A semi-additive measure can be summed across some dimensions (store, product, account) but not across time: summing the stock level of every day in a month is meaningless. Examples: inventory on hand, bank balance, headcount, number of open tickets.

The typical source is a snapshot fact table with one row per entity per day (or per month), for example FactInventory (Date, ProductKey, UnitsOnHand). Agree whether closing means the last calendar day, the latest observed date in the period, or each entity’s latest known snapshot. Those definitions give different results when snapshots are missing or arrive on different days.

Closing balance patterns

DAX
-- Simple: last date in the current filter context that has data for the snapshot
Closing Stock =
CALCULATE (
    SUM ( FactInventory[UnitsOnHand] ),
    LASTDATE ( FactInventory[SnapshotDate] )
)

-- Safer when the last day of a period may have no snapshot
Closing Stock (last non-blank) =
CALCULATE (
    SUM ( FactInventory[UnitsOnHand] ),
    LASTNONBLANK ( DimDate[Date], CALCULATE ( COUNTROWS ( FactInventory ) ) )
)

-- Built-in shortcuts
Closing Stock EOM = CLOSINGBALANCEMONTH ( SUM ( FactInventory[UnitsOnHand] ), DimDate[Date] )
Closing Stock EOY = CLOSINGBALANCEYEAR ( SUM ( FactInventory[UnitsOnHand] ), DimDate[Date] )
Opening Stock = OPENINGBALANCEMONTH ( SUM ( FactInventory[UnitsOnHand] ), DimDate[Date] )

How they differ:

Function Behaviour When to use
LASTDATE Last date in the current filter context Snapshots exist for every day, or you use the snapshot table's own date
LASTNONBLANK ( dates, expression ) Last date for which the expression is not blank Weekends or missing days without snapshots
CLOSINGBALANCEMONTH/QUARTER/YEAR Value at the last date of the period containing the current dates Quick, readable closing balance
OPENINGBALANCE… Value at the day before the period starts Opening balances

Measure the cost of scanning dates with LASTNONBLANK on large models. A fact-date LASTDATE can be simpler for a shared snapshot date. A fixed month-end flag alone does not choose one snapshot for a year total.

DAX formula bar: Closing Stock = CALCULATE ( SUM ( Inventory[UnitsOnHand] ), LASTDATE ( Inventory[SnapshotDate] ) )

DAX formula bar: Closing Stock EOM = CLOSINGBALANCEMONTH ( SUM ( Inventory[UnitsOnHand] ), 'Date'[Date] )

For a report that only shows the current position, a source table containing one latest snapshot per entity can also work. A report that must change the closing date with the selected period needs logic that selects the applicable date or dates. Default summarization cannot do that.

Worked example: month-end headcount

Scenario. HR stores FactHeadcount (SnapshotDate, DepartmentKey, Employees) with one row per department on the last day of each month. A matrix with months as columns and departments as rows should show employees at the end of each month, and the Total column (the year) should show the figure for December, not the sum of twelve months.

Step 1. A plain SUM ( FactHeadcount[Employees] ) adds twelve month-end counts in the year total. That is not the December count unless the other months are all zero.

Stock matrix: the 2025 Stock (Sum) total adds twelve month-end snapshots (42,759) while Closing Stock shows the December value (3,185); for 2026 Closing Stock EOM is blank because the calendar year ends after the last snapshot

Step 2. Write Employees EOP = CALCULATE ( SUM ( FactHeadcount[Employees] ), LASTDATE ( FactHeadcount[SnapshotDate] ) ). For the month of March, LASTDATE keeps 31 March; for the year, it keeps 31 December of the filtered year (the last snapshot date existing in the context).

Step 3. Add the department rows. If departments share a snapshot date, the subtotal sums their counts for that date. If departments load on different dates, the total recalculates at the last date for the whole selection. If the business wants each department’s latest value, iterate department keys and calculate the balance for each before summing.

Step 4. If the company sometimes loads snapshots on the 30th rather than the 31st, LASTDATE still works because it uses the dates present in the fact table. If you used DimDate[Date] there, you would need LASTNONBLANK instead, because the last calendar date has no row.

Why the alternatives are worse. AVERAGE would hide the true closing value. MAX ( Employees ) returns the largest department, not a total. Summing and dividing by 12 gives an average headcount, a different metric.

4. Calculation groups

A calculation group is a table with one column whose rows are calculation items. Each item is a DAX expression that modifies whatever measure is being evaluated, using SELECTEDMEASURE() as a placeholder. They remove the need to write Sales YTD, Margin YTD, Units YTD, Sales PY, and so on, for every base measure: you write the YTD logic once and the user (or visual) applies it to any measure.

DAX
-- Calculation group: Time Calculation, column Time Calc
Current:  SELECTEDMEASURE ()
YTD:      CALCULATE ( SELECTEDMEASURE (), DATESYTD ( DimDate[Date] ) )
PY:       CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( DimDate[Date] ) )
YoY %:    DIVIDE ( SELECTEDMEASURE () - CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( DimDate[Date] ) ),
                   CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( DimDate[Date] ) ) )

With this calculation group, a matrix with Time Calc on columns and measures [Total Sales], [Margin] on rows gives all combinations from a handful of definitions.

Creating them

In Power BI Desktop, open Model view and use Calculation group in the ribbon (or the Data pane), then add calculation items in the Properties pane or in the DAX editor. You can also use Tabular Editor. Creating a calculation group in Desktop requires, as of the current product, that you accept to discourage implicit measures (the model setting DiscourageImplicitMeasures is turned on), because calculation groups only apply to explicit measures. Implicit measures, created by dragging a numeric column to a visual, are not modified by calculation items.

Warning shown when adding the first calculation group: implicit measures will be discouraged in the model

Calculation item in the DAX formula bar: YTD = CALCULATE ( SELECTEDMEASURE (), DATESYTD ( 'Date'[Date] ) )

Model pane: the Time Calculation group with its column and the items Current, PY, YoY % and YTD

Format strings

A percentage item must not show 1,234.00 for a growth rate. Each calculation item has a format string expression:

Properties of the YoY % calculation item: dynamic format string turned on with "0.0%"

DAX
-- Format string expression for the YoY % item
"0.0%"

-- For items that must keep the base measure format
SELECTEDMEASUREFORMATSTRING ()

Precedence

When a model has several calculation groups (for example Time Calculation and Currency Conversion), the group's Precedence property determines which one is applied first. The higher precedence item forms the outer expression. The lower precedence item is substituted into its measure reference. Check the expanded expression and totals when combining time and currency logic.

Properties of the Time Calculation group with its Precedence value

Limits and tips

  • Calculation groups need explicit measures and a Power BI semantic model at compatibility level 1500 or higher.
  • Row-level security and calculation groups can coexist; calculation groups do not expose data, they change calculations.
  • Sorting items: use the Ordinal property so the items appear in a logical order.
  • Use ISSELECTEDMEASURE ( [Measure1], [Measure2] ) inside an item to apply different logic to specific measures, for example not computing YoY % on a measure that is already a ratio.
  • Visual calculations, a different feature, work inside the visual; calculation groups work in the model for all reports.

One measure, four columns: the Time Calc column in the matrix columns turns Total Sales into Current, PY, YoY % (formatted 0.0%) and YTD

Comparison: three ways to deliver "YTD for every measure"

Approach Effort Reuse Weakness
One YTD measure per base measure High None Dozens of near-identical measures
Quick measure (YTD) Low Per measure Generates a measure each time, still duplicated
Calculation group Medium (once) All explicit measures Needs explicit measures, precedence management

5. Common pitfalls and exam tips

  • For classic time intelligence, check the marked date table, its range, and the active fact relationship when results are blank or unexpected. Also verify that the prior period actually contains data.
  • Using the fact date column on the axis: time intelligence breaks. Use the date table's columns.
  • Auto date/time: the hidden date tables created automatically work, but they increase model size and are discouraged in favour of one shared date table.
  • DATEADD vs PARALLELPERIOD: partial selection versus whole period.
  • Summing a balance over time: use a closing balance pattern.
  • LASTDATE vs LASTNONBLANK: LASTDATE takes the last date visible in its input. LASTNONBLANK takes the last date whose test expression is nonblank.
  • Implicit measures with calculation groups: the group has no effect on them.
  • Role-playing dates: to compute time intelligence on the ship date, use USERELATIONSHIP inside CALCULATE, or a second date table.
  • Exam tip: when the question says "avoid creating many similar measures", think calculation group; when it says "closing balance", think CLOSINGBALANCE…, LASTDATE or LASTNONBLANK.

6. Mini case study

Situation. Fabrikam Logistics stores daily parcel volumes in FactParcels (Date, DepotKey, Parcels) and a weekly inventory of vans in FactVans (WeekEnding, DepotKey, VansInService). Reports need: (1) parcels year-to-date and the same figure last year; (2) the number of vans in service at the end of each month; (3) both YTD and prior-year views for four measures without creating eight extra measures. A DimDate table exists but is not marked as a date table, and one report page shows blanks for last year.

Question. What do you change, and which measures do you write?

Solution, commented.

  1. Mark DimDate as a date table and verify it has contiguous dates, and that the relationships connect FactParcels[Date] and FactVans[WeekEnding] to DimDate[Date]. Check the date-table configuration and which fields the visual uses. Verify there are prior-year fact rows before concluding what caused the blanks.
  2. Parcels YTD with CALCULATE ( [Total Parcels], DATESYTD ( DimDate[Date] ) ) and Parcels PY with SAMEPERIODLASTYEAR; no need for separate measures if step 4 is done.
  3. Vans at month-end is semi-additive: Vans EOM = CALCULATE ( SUM ( FactVans[VansInService] ), LASTNONBLANK ( DimDate[Date], CALCULATE ( COUNTROWS ( FactVans ) ) ) ). This returns the last common week-ending with data in the month. If depots report asynchronously, agree whether to use a common date or calculate each depot’s last available balance separately. LASTDATE on DimDate would return the calendar date even if the resulting balance were blank.
  4. Calculation group Time Calculation with items Current, YTD and PY, applied to the four explicit base measures. Accept the model setting to discourage implicit measures. Format items with SELECTEDMEASUREFORMATSTRING().

Why not the alternatives. Summing VansInService across weeks would count the same vans four or five times. Creating eight additional measures works but is error-prone to maintain. A quick measure for each would still produce eight objects.

Key terms

  • Date table: contiguous dimension with one row per day, marked as date table.
  • Time intelligence: DAX functions that shift or expand date filters.
  • YTD / QTD / MTD: period-to-date calculations.
  • Semi-additive measure: can be summed over some dimensions but not over time.
  • Snapshot fact table: table of periodic states (balances, stock).
  • Calculation group: table of calculation items modifying measures.
  • Calculation item: DAX expression using SELECTEDMEASURE().
  • Precedence: order of evaluation between calculation groups.
  • Explicit measure: measure created with DAX, required by calculation groups.

Summary checklist

  • I can build and mark a contiguous date table and relate it to the facts.
  • I can write YTD, prior-year, growth and rolling-window measures.
  • I know the difference between DATEADD and PARALLELPERIOD.
  • I can explain why balances are semi-additive and write a closing-balance measure.
  • I can choose between LASTDATE, LASTNONBLANK and CLOSINGBALANCE….
  • I can create a calculation group with SELECTEDMEASURE() and set format strings and precedence.
  • I know calculation groups require explicit measures.

Official sources