DAX queries

Measures calculate in visuals, queries return tables. In the DAX query view of Power BI Desktop you write a query with EVALUATE and see the result straight away, ideal for checking measures.

In short: a query starts with EVALUATE and a table, for example SUMMARIZECOLUMNS(Product[Category], "Sales", [Total Sales]). ORDER BY sorts, and DEFINE MEASURE before it creates a measure for this query only.

Before this: LOOKUPVALUE and RELATEDTABLE.

Try it now

Task Write a DAX query: one row per category with the column "Sales" from [Total Sales], the category with the highest sales at the top.

Sales 120 rows, 7 columns
OrderIDOrderDateShipDateProductIDRegionIDQuantityAmount
13 Oct 20266 Oct 20261221798
29 Nov 202519 Nov 20252351145
320 Sep 202627 Sep 2026544596
416 Jun 20252 Jul 20252151145
526 Mar 202631 Mar 20261343596
64 Dec 202510 Dec 2025545745
78 Jul 202526 Jul 2025614196
820 Feb 20251 Mar 202532359.7
99 Dec 202524 Dec 202562298
1012 Aug 202625 Aug 2026212458
117 Sep 202612 Sep 2026542298
122 Mar 202614 Mar 2026623147

Showing the first 12 of 120 rows.

Measures: [Total Sales]

Product 6 rows, 4 columns
ProductIDProductCategoryPrice
1LaptopHardware899
2MonitorHardware229
3MouseAccessories19.9
4KeyboardAccessories39.9
5Office suiteSoftware149
6AntivirusSoftware49
Region 4 rows, 2 columns
RegionIDRegion
1North
2South
3West
4East
Date 730 rows, 4 columns
DateYearMonthMonthName
1 Jan 202520251Jan
2 Jan 202520251Jan
3 Jan 202520251Jan
4 Jan 202520251Jan
5 Jan 202520251Jan
6 Jan 202520251Jan
7 Jan 202520251Jan
8 Jan 202520251Jan
9 Jan 202520251Jan
10 Jan 202520251Jan
11 Jan 202520251Jan
12 Jan 202520251Jan

Showing the first 12 of 730 rows.

Structure of a query

DEFINE
    MEASURE Sales[Avg Amount] = AVERAGE(Sales[Amount])
EVALUATE
SUMMARIZECOLUMNS(
    Region[Region],
    "Avg Amount", [Avg Amount]
)
ORDER BY [Avg Amount] DESC
  • DEFINE (optional): measures, variables and columns that only apply in this query.
  • EVALUATE: any table, so also FILTER, TOPN, ADDCOLUMNS or simply the name of a table.
  • ORDER BY: columns with ASC (the default) or DESC. Without ORDER BY the order is not defined.

SUMMARIZECOLUMNS is the function Power BI uses to fetch the data of every visual: group columns, then pairs of name and expression. Rows in which every expression is blank are dropped, as in a matrix.

The top three

Task Write a DAX query for the three best-selling products: columns Product and "Sales", sorted descending.

Sales 120 rows, 7 columns
OrderIDOrderDateShipDateProductIDRegionIDQuantityAmount
13 Oct 20266 Oct 20261221798
29 Nov 202519 Nov 20252351145
320 Sep 202627 Sep 2026544596
416 Jun 20252 Jul 20252151145
526 Mar 202631 Mar 20261343596
64 Dec 202510 Dec 2025545745
78 Jul 202526 Jul 2025614196
820 Feb 20251 Mar 202532359.7
99 Dec 202524 Dec 202562298
1012 Aug 202625 Aug 2026212458
117 Sep 202612 Sep 2026542298
122 Mar 202614 Mar 2026623147

Showing the first 12 of 120 rows.

Measures: [Total Sales]

Product 6 rows, 4 columns
ProductIDProductCategoryPrice
1LaptopHardware899
2MonitorHardware229
3MouseAccessories19.9
4KeyboardAccessories39.9
5Office suiteSoftware149
6AntivirusSoftware49
Region 4 rows, 2 columns
RegionIDRegion
1North
2South
3West
4East
Date 730 rows, 4 columns
DateYearMonthMonthName
1 Jan 202520251Jan
2 Jan 202520251Jan
3 Jan 202520251Jan
4 Jan 202520251Jan
5 Jan 202520251Jan
6 Jan 202520251Jan
7 Jan 202520251Jan
8 Jan 202520251Jan
9 Jan 202520251Jan
10 Jan 202520251Jan
11 Jan 202520251Jan
12 Jan 202520251Jan

Showing the first 12 of 730 rows.

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

In real Power BI

  1. Open DAX query view in the bar of views on the left.
  2. Write the query and click Run. The result appears below as a table.
  3. In the Data pane, the context menu of a table or measure offers ready-made queries to try under Quick queries.

Common mistakes

Forgetting EVALUATE

A query without EVALUATE is a syntax error, even if the table in it is right.

A number instead of a table

EVALUATE [Total Sales] does not work; EVALUATE needs a table. For a single value: EVALUATE ROW("Sales", [Total Sales]) or EVALUATE {[Total Sales]}.

FAQ

Does a query change my model?

No. Measures from DEFINE only apply to the query, until you explicitly add them to the model.

Where else do such queries run?

For example in the free tools DAX Studio and Tabular Editor, which connect to an open Power BI model.

Up next: year over year project

Previous year, change, rank and best month per region.

Go to the project

Write to us

Choose language

Select your preferred language