Back to Roadmap
Level 5 — Real-World DAX Patterns+75 XP
Lesson 1
1. Variables (VAR and RETURN)
Boost readability, debugging, and eliminate redundant calculations.
The Concept
Variables store the result of an expression as a constant within the scope of the formula.
Example DAX:
YoY Growth % =
VAR CurrentSales = [Total Revenue]
VAR PreviousSales = CALCULATE([Total Revenue], SAMEPERIODLASTYEAR('Date'[Date]))
RETURN
DIVIDE(CurrentSales - PreviousSales, PreviousSales, 0)Variables are evaluated once when defined. Re-referencing CurrentSales 5 times does NOT recalculate the measure 5 times!
Try It Yourself
Write a measure calculating Margin using VAR TotalRev, VAR TotalCost, and RETURN TotalRev - TotalCost.
fx
[fx]Variables (VAR and RETURN)=
Loading DAX Formula Studio...
Type [ for fields