Stop 09 · Advanced DAX PatternsTopics · 6/10

Table Functions (SUMMARIZE, ADDCOLUMNS, VALUES)

Part of the Power BI Roadmap

In short

Some questions need a small table first: "what's the average monthly sales?" needs a list of months and their sales before you can average. Table functions build these invisible tables inside your measures.

Table functions return tables instead of single values. VALUES lists unique values, SUMMARIZE groups by columns, and ADDCOLUMNS adds calculated columns, which together build virtual tables inside measures.

The jaadu scribbles a small grid on a scrap of paper beside a big exam sheet, then circles a single answer box on the main sheet.

Think of it like this

The rough worksheet

Before giving the final answer in a maths exam, you scribble a small table on the rough page: one line per month, its total next to it. Then you average that column. The examiner only sees the final number. VALUES, SUMMARIZE and ADDCOLUMNS are that rough page, built and thrown away inside the measure.

Watch it happen

Building a virtual table step by step

Best Category Sales (one number)
MAXX over the table
ADDCOLUMNS: add @CatSales
SUMMARIZE ( Sales, Product[Category] )
Grocery, Snacks, Beverages, Personal Care

1/5SUMMARIZE groups Sales by Category, giving one row per category that has sales.

The big ideas

What you need to know

VALUES: unique list

VALUES ( 'Date'[Month Start] ) returns the distinct months visible in the current filter context.

SUMMARIZE: group by

Use SUMMARIZE only to list column combinations, for example SUMMARIZE ( Sales, Product[Category], Customer[Region] ).

ADDCOLUMNS: compute

Add calculated columns with ADDCOLUMNS. Measures inside it get context transition, so each row gets its own value.

Iterators finish the job

AVERAGEX, MAXX, SUMX and COUNTROWS turn the virtual table back into one number for the measure.

See it in code

Walk through the code

dax
1Avg Monthly Sales =2AVERAGEX (3    VALUES ( 'Date'[Month Start] ),4    [Total Sales]5)6 7Best Category Sales =8MAXX (9    ADDCOLUMNS (10        SUMMARIZE ( Sales, Product[Category] ),11        "@CatSales", [Total Sales]12    ),13    [@CatSales]14)15 16Categories Above 10L =17COUNTROWS (18    FILTER ( VALUES ( Product[Category] ), [Total Sales] > 1000000 )19)

1/4One row per visible month, each with its own Total Sales, then averaged.

Three measures that build a table first and return one number at the end.

Save yourself the pain

Common mistakes

Oops

Adding calculated values inside SUMMARIZE with extra name and expression pairs.

Do this instead

That older style can give wrong results. Use SUMMARIZE only for grouping and ADDCOLUMNS for calculations.

Oops

Using AVERAGE ( Sales[Amount] ) for average monthly sales.

Do this instead

That averages order lines, not months. Iterate over VALUES of a month column instead.

Your mission

See your virtual table

~25 min

Quick check

What does VALUES ( Product[Category] ) return inside a measure?

Go deeper

  1. 1Use VALUES inside an iterator to loop over customers.
  2. 2Build a virtual table of sales per customer with ADDCOLUMNS and VALUES.
  3. 3Test table expressions with New table or DAX query view before using them in measures.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge