There are several undocumented DAX formula bar keyboard shortcuts in Power BI Desktop. For instance, you can comment or uncomment portions of your code, go to a specific line of code, and do other things. Some of the keyboard shortcuts are more useful than others — this blog post lists all that I am aware of.
Comment/uncomment
If you need to comment out one line, you can use two hyphens (—) or two forward slashes (//) in front of it. Multi-line comments need to be enclosed between /* and */. Alternatively, you can use keyboard shortcuts.
- To comment a portion of your code, highlight it and press Alt + Shift + A
Alternatively, press Ctrl + / - To uncomment a piece of code, highlight part of it and press Alt + Shift + A
Alternatively, press Ctrl + /
Unfortunately, each keyboard shortcut does not recognize the comments that were created by the other keyboard shortcut as comments, so it does not uncomment them.
Increase/decrease indent
A good programmer always formats their code. This includes using proper indentation for different. DAX Formatter, which I highly recommend, does this automatically for you, but you can also increase and decrease indents manually by using keyboard shortcuts instead of typing spaces.
- To increase indent, highlight a line or part of it and press Tab
Alternatively, press Ctrl + ] - To decrease indent, move the cursor to a line (highlighting code is not necessary) and press Shift + Tab
Alternatively, press Ctrl + [
Multiple selections
Sometimes you may need to type in multiple places at once. For example, you may want to replace all instances of one measure with another measure. To save you the trouble of doing Replace All in a text editor, you can use keyboard shortcuts.
There are several keyboard shortcuts that can help you in this case:
- Ctrl + D selects the whole word; if a segment has already been selected, it selects the next instance of the same word. by pressing Ctrl + D for the second time, you select the next instance of the same segment. You can then type in multiple selections.
- Ctrl + F2 or Ctrl + Shift + L selects all instances of a word/selection.
- Ctrl + Alt + Up or Ctrl + Alt + Down create multiple cursors so you can type in multiple places.
To finish typing, press Enter.
Go to line number
Sometimes your DAX formula is very long, and you may need to navigate without scrolling. A good example would be the DAX Date Template by SQLBI — over 1000 lines! Scrolling might be difficult in this case; a viable alternative is navigating by line number.
To go to a specific line number, press Ctrl + G, then type the line number (the line will be highlighted in yellow) and press Enter or click on any code line to remove the line number bar.
Remove one or more lines
If, for whatever reason, you feel like using a keyboard shortcut for deleting one or more lines, go to the line (for multiple lines, highlight them; partial highlighting is sufficient) and press Ctrl + Shift + K.
Bring IntelliSense
When you type your DAX formulas, IntelliSense suggests you functions or objects that it thinks may be useful. To select a suggestion, you can use the arrow keys on your keyboard, and to accept a suggestion, you can press Tab.
If you closed IntelliSense, you can bring it back by pressing Alt + I.
For some reason, many other keyboard shortcuts, such as Alt + U, Alt + G, etc. perform a similar function.
Line break
Chris Webb has already blogged about using Shift + Enter for line breaks earlier this week, which auto-indents your code if necessary. I didn’t record a GIF for this one because Chris’s GIF is quite nice 🙂
You can also press Alt + Enter if you don’t want your code to be indented.
Reorder lines
If you want to reorder lines, you can do so either by cutting and pasting, or you can use a keyboard shortcut:
- To move the selected lines up, press Alt + Up
- To move the selected lines down, press Alt + Down
Copy lines
You can copy lines by employing the usual Ctrl + C and Ctrl + V pair of keyboard shortcuts, or you can use one of the following two:
- To copy and paste above the selected lines, press Alt + Shift + Up
- To copy and paste below the selected lines, press Alt + Shift + Down
Expand selection
You can select the nearest word and successively expand selection by pressing Alt + Shift + Right.