When you write a DAX formula that is not trivial, you end up having a complex expression that is not really readable. I think that the same problem affect in part all Excel users, but in Excel you can easily split a formula in many steps, using different cells. This is not always possible in Tabular, because moving a sub-expression in a separate measure might change the semantic, and this operation is possible only for scalar values and not for function tables. So we need to write readable code.
One year ago, we published the Rules for DAX Code Formatting. Today, I’m prod to announce the availability of DAX Formatter, a free service that automatically format the code following these rules. We designed the service to be easy to use. Type the DAX expression (or paste it) and press Format. That’s it.
For those of you reading offline or too lazy to click on a link, here is how it works. Suppose you have this DAX query (but you can format also expressions for measures and calculated columns):
EVALUATE ADDCOLUMNS(FILTER(CROSSJOIN( SUMMARIZE(Customer,Customer[Customer],Customer[Customer.Key0]), VALUES('Date'[Date.Key0])),NOT ISBLANK([Internet Sales Amount])), "Sales",[Internet Sales Amount]) ORDER BY 'Date'[Date.Key0] DESC,Customer[Customer] ASC
You paste it into DAX Formatter and you obtain this result:
EVALUATE ADDCOLUMNS ( FILTER ( CROSSJOIN ( SUMMARIZE ( Customer, Customer[Customer], Customer[Customer.Key0] ), VALUES ( 'Date'[Date.Key0] ) ), NOT ISBLANK ( [Internet Sales Amount] ) ), "Sales", [Internet Sales Amount] ) ORDER BY 'Date'[Date.Key0] DESC, Customer[Customer] ASC
Which is also more readable in the web site thanks to the layout available (you can choose between dark and light color scheme):
And if you use non-US locale, just select the separators for you.
Please, Submit any bug using the Bug Report button.
Currently you can format any DAX query and expression in the form:
- EVALUATE …
- Table[measure] := …
- [measure] := …
- Table[column] = …
- = …
- measure := …
Feedback are welcome – enjoy!