DAX query view in Power BI

With DAX query view in Power BI, we can view and work with Data Analysis Expressions (DAX) queries in semantic models. DAX queries can be used to return data from the model. DAX queries don't create items in the model or visuals in the report.

DAX queries have two main parts:
• An EVALUATE statement, which is required. It specifies what and how data is returned in the query.
• A DEFINE statement, which is optional. It allows us to define DAX formulas, such as a measure, to use in the query.

Open DAX query view In Power BI Desktop, select the DAX Query View icon on the left side.

DAX query view in Power BI

DAX query view has following elements: 1. Ribbon The DAX query view ribbon has common actions used when writing DAX queries.

DAX query view in Power BI

Let's take a closer look at elements in the ribbon: a) Format query Click the Format query ribbon button or use SHIFT+ALT+F to format the current query. The query is indented with tabs. DAX functions are changed to UPPERCASE, and additional lines are added. Formatting our DAX query is considered a best practice and improves the DAX query readability. The formatting also indents in such a way that we can collapse and expand sections of the query.

b) Comment and Uncomment Click the Comment ribbon button to add a double backslash (//) to the beginning of the line where the cursor is or all the selected lines. This comments out the lines and when the DAX query is run, those lines are ignored.

Click the Uncomment ribbon button to remove // at the beginning of any line where the cursor is, or all the selected lines. It doesn't work on lines where multiple line comment notation is added.

We can also use CTRL+/ to toggle between comment and uncomment.

c) Find and Replace Click on the Find ribbon button or use CTRL+F to search for text in the DAX query editor. Find includes options to match case, match whole word, use a regular expression, and cycle through all matches for the current query. We can also click the chevron to the left of the Find box to enter Replace.

Click on the Replace button in the ribbon or use CTRL+H to search for and replace text in the DAX query editor. Replace includes options to preserve the case and replace one at a time or all at once.

d) Command palette Click the Command palette ribbon button or use CTRL+ALT+P to open the command palette box. We can search for additional DAX query editor actions and see their associated keyboard shortcuts.

2. Command bar The DAX query view command bar includes the most important actions when using DAX query view. The Run button executes the DAX query or the selected lines of a query. The status of a query after it runs appears in the lower status bar.

DAX query view in Power BI

When a query is running, the button becomes a Cancel button, which can be used to stop a running query.