When you’re dealing with a beast like DAX you can use any help there is, right? So here I show you how you can debug DAX variables who contain tables or show the result of multiple variables at once. So you can easily compare them with each other to spot the reason for problems fast.
Please note, that currently only comma separated DAX code is supported.
Watch this measure from Gerhard Brueckl’s brilliant solution for dynamic TopN clustering with others. It contains 5 variables who return tables and one variable with a scalar:
If you want to follow along how this calculation is evolving for each value in a matrix, my VarDebugMeasure will show details of every variable like so:
This method is a variation of my previous blogpost, which made the elements of tables in a CALCULATE function visible. Cool thing with the new function for variables is, that you can see details of all your variables in one measure (see picture above).
Code to debug DAX variables
Because one cannot paste text with linebreaks into the function dialogue in the query editor, I opted for a separate query that holds the code from the measure with the variables to investigate. If you name it “DAXVariableMeasureCode” like the default in the function, all have to do is to fill in the first parameter of the function like so:
- A comma separated text string that lists one value for each variable: If the variable represents a table, then the column name whose values shall be shown. For scalars, the null-value has to be entered.
- Optional: Number for how many sample values shall be shown. Default value is 10. So if you want to change it, just put in a different number in here.
- Full code of the measure that includes the variable (including the measure name)
6 steps to wow
- Copy the function code:
- Create a new query in the query editor and replace the existing code with the copied code (Strg+A, Strg+V)
- Create another new query (named “DAXVariableMeasureCode”) where you paste the DAX-code of the measure that contains the variables.
- Call the function with the parameters described under “Code parameters”. In my example, this looks like so:
- Copy the resulting DAX code
- Create new measure where you paste the copied DAX code
- Drag that measure into a table or matrix beside the original measures
Please follow along these steps in this video:
You can download the file with examples here: Debug DAX Variables
Enjoy & stay queryious 😉