Last week, at the SQL Server Days conference in Belgium, Kasper mentioned in his presentation that it was possible to define variables inside variables in DAX. So, for example, you could define a measure like so:
[sourcecode language='text' padlinenumbers='true'] MyMeasure = var Outer1 = var Inner1 = 1 var Inner2 = 2 return Inner1 + Inner2 var Outer2 = 3 return Outer1 + Outer2 [/sourcecode]
This measure returns 6 as you might expect:
There aren’t any performance benefits to doing this, although of course it helps with code readability and organisation (thanks to Marius for confirming this).
With my newly rekindled love of DAX I thought this was quite interesting. I’m not really sure why though, given that it’s not particularly useful; I think Matt might be right: