The other day I discovered something new (at least to me) while writing the DAX for a measure in Power BI Desktop: when you insert a new line in your DAX expression using SHIFT-ENTER it also auto-indents the code. I asked a few people if this was new because I was sure I hadn’t seen it before, even though I always put line breaks in my code; of course Marco had and said he thought it had been around for a while. Anyway, Marco then commented that most people didn’t know you could even put line breaks in DAX and I thought to myself I should probably write a short blog post about all this, because of course line breaks and indentation make your code much more readable.
Here’s what it looks like to write a DAX measure in Power BI Desktop using line breaks and auto-indent:
To summarise:
- Press the SHIFT and ENTER keys on the keyboard simultaneously to insert a line break in your DAX code when you are working in the Power BI DAX formula bar
- Do this after the opening bracket of each function and after the comma of each function argument and the auto-indent will kick in
- Bonus tip: while typing DAX, if the dropdown list has the function, table, column or measure selected that you want to use, just hit the TAB key to auto-complete. If the dropdown list hasn’t selected what you are looking for and you don’t want to keep typing, use the up and down arrow keys on the keyboard to move up and down the list until you have selected what you want.
Of course there’s always Marco and Alberto’s excellent DAX Formatter service to format your DAX code but this is a lot more convenient.
Thanks. I use SHIFT-ENTER frequently in Excel and Word but hadn’t realized I could use it while writing DAX code. I’ll still use the DAX formatter at http://www.daxformatter.com/ for longer code :).
Your blog post prompted me to write about something I’ve been sitting on for a while: undocumented DAX formula bar keyboard shortcuts 🙂
https://xxlbi.com/blog/dax-formula-bar-keyboard-shortcuts-in-power-bi-desktop/
Thanks for the tips.
Here another tip:
By using ALT+ENTER (instead of SHIFT+ENTER) you get a linke break without identation.