DAX formulas can quickly become very complicated and difficult to read especially when you start to combine many functions in one single formula.
Variables in a DAX is a way of breaking down parts of a formula into smaller defined parts.
Let’s take a look at this simple DAX formula below:
How easy is it to interpret that?
That entire formula can be re-written, making use of Variables to break things down in a more explainable way.
Then it can look like the image below:
After making use of variables, the different units of the formula have been broken down to make readability a lot easier.
Trust me, it also makes writing the formula easier as well.
Apart from the fact that variables improves readability, reduces complexity and makes it easier to author DAX formulas, it also improves performance of DAX formulas.
To use variables in DAX, you need to:
Also note that, you can also define all the legs as variables, including the output leg.
Then to complete the formula, precede the variable you want to output with the RETURN keyword as shown below.
Need to learn more about variables? Check out the Microsoft Documentation