DAX queries: EVALUATE, DEFINE and DAX query view

How to write DAX queries with EVALUATE, DEFINE, ORDER BY and START AT, test measures in Power BI's DAX query view, quick queries, updating the model from query-scoped measures, CodeLens, and examples for checking numbers and exploring tables.

Short answer: a DAX query returns a table from the model. It needs EVALUATE followed by a table expression, and can start with DEFINE to declare measures, variables, columns or functions for the query. In Power BI Desktop, DAX query view (the fourth view on the left) runs queries, shows the result grid, writes queries for you (quick queries), and saves query-defined measures into the model with Update model with changes. It is the fastest way to test a measure without building a visual.

Testing a measure in a report means building a table visual, adding fields and filters, and reading the numbers. In DAX query view it is three lines, with the result in a grid you can copy, and the formula editable next to it.

What does a DAX query look like?

DEFINE
    MEASURE Sales[Revenue LY] =
        CALCULATE ( [Revenue], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
    VAR Years = { 2025, 2026 }

EVALUATE
SUMMARIZECOLUMNS (
    'Date'[Year],
    'Product'[Category],
    TREATAS ( Years, 'Date'[Year] ),
    "Revenue", [Revenue],
    "Revenue LY", [Revenue LY]
)
ORDER BY 'Date'[Year], [Revenue] DESC
KeywordDoes
DEFINEoptional; declares MEASURE, VAR, TABLE, COLUMN or FUNCTION for this query
EVALUATErequired; returns the table expression after it (several EVALUATE blocks are allowed)
ORDER BYsorts the result, ASC or DESC per column
START ATwith ORDER BY, starts the result at given values (paging)
The parts of a DAX query

Any table expression works after EVALUATE: a table name, FILTER, TOPN, SUMMARIZECOLUMNS. A single value needs braces: EVALUATE { [Revenue] }.

Which quick queries help most?

-- look at the first rows of a table
EVALUATE TOPN ( 100, Sales )

-- check a measure's total
EVALUATE { [Revenue] }

-- distinct values of a column with a count
EVALUATE
SUMMARIZECOLUMNS ( 'Product'[Category], "Rows", COUNTROWS ( Sales ) )

-- find keys in Sales without a product
EVALUATE
EXCEPT ( VALUES ( Sales[Product Key] ), VALUES ( 'Product'[Product Key] ) )

The last query returns the product keys that exist in Sales but not in Product: the rows that show as (Blank) in visuals.

In the Data pane, right-click a table, column or measure, Quick queries: Show top 100 rows and Show column statistics for tables and columns; Evaluate, Define and evaluate, and Define with references and evaluate for a measure; Define all measures in this table or in the model (up to 500 measures). Each writes the query for you; Show top 100 rows uses SELECTCOLUMNS with one column per line, so you can comment columns out.

How do you change measures from the query?

Measures in DEFINE MEASURE are query-scoped: they exist only while the query runs and override the model measure of the same name. That makes testing safe. When the change is right:

  • CodeLens above each DEFINE MEASURE: Update model: Add new measure or Update model: Overwrite measure.
  • Update model with changes in the command bar saves all of them at once.

Select a measure in an EVALUATE without DEFINE and the light bulb offers Define or Define with references, which writes the measure and the measures it depends on into a DEFINE block. Descriptions can be added with /// comments above a measure.

What else is in DAX query view?

  • Format (Shift+Alt+F), comment (Ctrl+/), find and replace (Ctrl+F, Ctrl+H), command palette (Ctrl+Alt+P).
  • Several query tabs, saved in the file from Power BI Desktop; queries can run in the background while you work in another tab.
  • Several EVALUATE statements return several results; the Result dropdown switches between them, and Copy copies the grid.
  • Copilot can write and explain queries, where available.

What goes wrong?

  • EVALUATE [Measure]. A measure is a scalar; wrap it in braces: EVALUATE { [Measure] }.
  • Forgetting the model is untouched. Query-scoped measures disappear; save with CodeLens or Update model.
  • Filters missing. A query has no slicers; add filters with TREATAS, CALCULATETABLE or FILTER to match the report.
  • Huge results. EVALUATE Sales on 50 million rows is slow; use TOPN.

Where can you check this?

Where do you start?

Open DAX query view, right-click your main measure and pick Define and evaluate, then change the formula and run it until the number is right. SUMMARIZECOLUMNS is the function most queries are built on.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.