---
title: "Get the DAX query behind a visual"
description: "Three ways to get a DAX query without writing it — Performance Analyzer copies the query of any visual, DAX query view's Quick queries, DAX Studio's query builder"
url: "https://docs.justcat.it/how-to-guides/data-platforms/power-bi/get-the-dax-query-behind-a-visual/"
---
# Get the DAX query behind a visual


## 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 **measure** → **Evaluate** writes `EVALUATE SUMMARIZECOLUMNS(…, "Measure", [Measure])` — add the group-by columns you want (year, country) and you have the query a measure test needs;
* a **table** → **Show top 100 rows**; a **column** → **Show 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

<a href="https://daxstudio.org" target="_blank">DAX Studio</a> 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](dax-studio-connect.png)

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](dax-studio-query-builder.png)

```dax
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](https://docs.justcat.it/reference/data-sources/providers/powerbi-2/ "PowerBI@2") for an open Desktop file, [Dax@2](https://docs.justcat.it/reference/data-sources/providers/dax-2/ "Dax@2") for a workspace or Analysis Services model. In CAT Studio the test editor runs the DAX for you before you save.

## Related

* [Test measures](https://docs.justcat.it/how-to-guides/data-platforms/power-bi/test-measures/ "Test measures") — what to do with the query once you have it.
* [DAX for SQL people](https://docs.justcat.it/how-to-guides/data-platforms/power-bi/sql-to-dax/ "DAX for SQL people") — when you would rather write it.
* [Test Power BI](https://docs.justcat.it/how-to-guides/data-platforms/power-bi/test-power-bi/ "Test Power BI") — the overview.

