Get Help

Get the DAX query behind a visual

Every number on a Power BI report is the result of a DAX query, and Power BI will hand that query to you. Paste it into a test and you are testing the number the user sees. Three ways, no DAX knowledge needed for the first two.

Performance Analyzer — the query of a visual

The report is open in Power BI Desktop (or you are editing it in the service).

  1. Optimize ribbon → Performance Analyzer (in the service: View → Performance Analyzer while editing).
  2. Start recording, then Refresh visuals — or click Analyze this visual in the corner of the one visual you care about.
  3. Expand the visual in the pane and select Copy query. (Run in DAX query view opens it in Desktop’s query view instead, where you can run it and trim it.)

That query returns exactly the table the visual shows. It is more verbose than a hand-written one — variables, TOPN, the visual’s sort — and it works as it is. If you want it shorter, DAX query view’s Copilot, or any AI assistant, simplifies it with a prompt like “Remove the VARs and TOPN and simplify this DAX query”; run the result and compare before you trust it.

DAX query view — a query from a measure, a table or a column

Power BI Desktop has a DAX query view (the icon on the left edge; in the service and in Fabric, Write DAX queries on a semantic model). Its Data pane has Quick queries on the context menu of every object:

  • a measureEvaluate writes EVALUATE SUMMARIZECOLUMNS(…, "Measure", [Measure]) — add the group-by columns you want (year, country) and you have the query a measure test needs;
  • a tableShow top 100 rows; a columnShow data preview (DISTINCT) — the shape of a completeness test.

Run it, look at the grid, copy the query. Queries you write here are saved with the .pbix, so the tests’ queries can live next to the model.

DAX Studio — a query builder

DAX Studio is a free external tool that connects to an open Desktop file, to a workspace model (XMLA endpoint — Premium, Premium per user or a Fabric capacity) or to an Analysis Services instance, and has a drag-and-drop Query Builder:

DAX Studio connection dialog

Drag columns and measures to the Columns / Measures pane, add filters, add a sort order — sort matters when the test is a sets match against another system — and Update builds the query:

DAX Studio query builder

SUMMARIZECOLUMNS (
    'DIM AIRLINES'[AIRLINE_NAME],
    "AVG Delay in Minutes", [AVG Delay in Minutes]
)

Run it (top left), check the result, copy the query.

Then

Paste the query into the test — the Query of a one-set test, First query or Second query of a comparison — exactly as you would a SQL statement. PowerBI@2 for an open Desktop file, Dax@2 for a workspace or Analysis Services model. In CAT Studio the test editor runs the DAX for you before you save.