5 Reasons to use Variables in your DAX Code
One of the hallmarks of getting better at BI is writing more complex DAX in columns and measures so I want to share with you guys by far the most helpful thing I´ve learned DAXwise - variables. The concept is really simple - you give a name to a value or a table with some DAX and you can then refer to it by its name in a final calculation or another variable. We´ll do the syntax then I´ll give 5 reasons why this simple concept is actually awesome. Syntax VAR <name> = <expression> ...repeat for as many variables as you like RETURN <expression> e.g. TwoPlusTwoEqualsFour = VAR a = 2 VAR b = 2 RETURN a+b 1. Troubleshooting We all know the feeling when you write a big string of code, hit return and then you get nothing, or every kid has the same number and you know you´ve messed up. Using variables allows you to check the various elements of the calculation without touching the other steps. For example, this is the formula for a...