Variables in DAX (VAR)
Use VAR to write cleaner, faster, and easier-to-debug DAX formulas
Variables in DAX (introduced with VAR...RETURN syntax) make complex DAX formulas dramatically more readable and slightly faster. Before variables, complex measures required nested functions that were hard to read and debug. With variables, you store intermediate results and refer to them by name.
Variables in DAX are not the same as variables in programming languages — they are evaluated once and are immutable (cannot change within the formula). But they are still one of the most powerful quality-of-life improvements in modern DAX.
Example
Key Points
- ✓VAR names are local — they only exist within the measure where defined
- ✓Variables are evaluated once — even if referenced multiple times in RETURN
- ✓This makes SUMX(table, VAR x = ... RETURN x * 2) technically possible but unusual
- ✓RETURN is required at the end — it is what the measure actually outputs
- ✓Use VAR for any measure with a repeated sub-expression
Practice Question
In a DAX measure using VAR...RETURN syntax, what does the RETURN statement do?