Calculation groups
Reuse an expression, not a copied measure
A calculation group contains named calculation items that transform an explicit model measure. Build Current, Prior year and Growth once, then apply them to Revenue or Units. Work only in a disposable Import model; the setup and source CSV are in labs/advanced-dax/README.md. The numerical outputs are predictions checked offline, not native execution results.
Create the time group
Create explicit measures [Revenue] = SUM(PeriodSales[Revenue]) and [Units] = SUM(PeriodSales[Units]). Create the contiguous date dimension LabDate = CALENDAR(DATE(2024,1,1), DATE(2025,12,31)), add Year = YEAR(LabDate[Date]), mark as date table and connect date to PeriodSales (1:*, single direction). Create a calculation group TimeCalc with column Item and three items. Set DiscourageImplicitMeasures. Calculation items are not standalone measures; insert their expressions in the item editor, not in New measure. Use a single item per cell; set the matrix year filter to 2025. No group relationship to the fact is needed.
Example 1 — current and prior
Current item:
SELECTEDMEASURE()Prior year item:
IF(ISSELECTEDMEASURE([Revenue], [Units]), CALCULATE(SELECTEDMEASURE(), SAMEPERIODLASTYEAR(LabDate[Date])), SELECTEDMEASURE())For the 2025 matrix by Category, Revenue A=150 vs 100, B=80 vs 100, C=30 vs 0, total=260 vs 200. Units A=15 vs 10, B=8 vs 10, C=3 vs 0. The year shift must change the measure evaluation context, not a stored scalar.
Example 2 — growth with a missing denominator
Growth item:
IF(ISSELECTEDMEASURE([Revenue], [Units]), VAR CurrentValue = SELECTEDMEASURE() VAR PriorValue = CALCULATE(SELECTEDMEASURE(), SAMEPERIODLASTYEAR(LabDate[Date])) RETURN IF(ISBLANK(CurrentValue) || ISBLANK(PriorValue), BLANK(), DIVIDE(CurrentValue-PriorValue, PriorValue)), SELECTEDMEASURE())A=50%, B=-20%, C=blank (zero baseline). Total=30%, because the ratio is evaluated at total scope. A category total is not an average of percentages. The model also returns blank for a missing prior value; a zero current with positive prior is -100%. Set Growth format in lesson 2.
Avoid accidental context freezing
If VAR x = SELECTEDMEASURE() is computed before a date shift, CALCULATE(x, ...) does not recompute the expression in the prior period. Pass the original measure expression to CALCULATE. Do not select multiple items expecting a combined transformation; explicitly configure and test no-selection, multiple-selection and subtotal policy on the installed engine. Do not apply a growth percentage to unrelated text measures. Calculation groups are documented for compatibility 1500+; do not attach RLS/OLS directly to a calculation-group table. See support matrix in the lab.
Practice — missing vs zero
Predict the Growth value for a new category with no prior record and current revenue 50. Then predict the result if prior revenue is 50 and current is recorded zero. Explain why the two blanks/zero cases differ. Next: format the same item and test precedence. References: https://learn.microsoft.com/en-us/analysis-services/tabular-models/calculation-groups?view=sql-analysis-services-2025; https://learn.microsoft.com/en-us/dax/selectedmeasure-function-dax; https://learn.microsoft.com/en-us/dax/isselectedmeasure-function-dax