Stop 07 · DAX FundamentalsTopics · 7/10

Iterator Functions (SUMX, AVERAGEX)

Part of the Power BI Roadmap

In short

Your Sales table has Qty and Unit Price but no Amount column. Iterators like SUMX calculate row by row and then add up, with no calculated column needed.

Iterators like SUMX evaluate an expression for each row of a table and then aggregate the results, for example SUMX ( Sales, Sales[Qty] * Sales[Price] ).

The jaadu, as a cashier, picks items one at a time off a conveyor belt at a supermarket billing counter and adds each to a growing receipt.

Think of it like this

The billing counter

The cashier picks up each item, multiplies quantity by price for that item, writes it down, and only at the end totals the bill. SUMX does exactly that: go row by row, compute an expression, then add up the results.

Watch it happen

SUMX ( Sales, Sales[Qty] * Sales[Unit Price] )

2 × 50
0
1 × 300
1
4 × 25
2
3 × 120
3

1/5The current filter leaves four sales rows.

The big ideas

What you need to know

Table, then expression

SUMX ( table, expression ). The expression runs once per row of the table, in row context.

Ends in X

SUMX, AVERAGEX, MINX, MAXX, COUNTX. Each aggregates the per-row results in its own way.

Iterate the right table

AVERAGEX ( VALUES ( Sales[BillNo] ), [Total Sales] ) averages per bill, not per line.

Watch the size

Iterating millions of rows with a complex expression can be slow. Keep the expression simple.

See it in code

Walk through the code

dax
1Revenue =2SUMX ( Sales, Sales[Qty] * Sales[Unit Price] )3 4Revenue After Discount =5SUMX (6    Sales,7    Sales[Qty] * Sales[Unit Price] * ( 1 - Sales[Discount %] )8)9 10Avg Bill Value =11AVERAGEX ( VALUES ( Sales[BillNo] ), [Revenue] )

1/3Multiply quantity by price on each row, then sum. No stored Amount column needed.

Three iterators. The last one iterates bills instead of lines.

Save yourself the pain

Common mistakes

Oops

Writing SUM ( Sales[Qty] ) * SUM ( Sales[Unit Price] ).

Do this instead

That multiplies two totals, which is wrong. Use SUMX so each row's qty multiplies that row's price.

Oops

Using AVERAGEX ( Sales, ... ) when you want an average per bill.

Do this instead

Iterate VALUES ( Sales[BillNo] ) so each bill counts once, whatever its number of lines.

Your mission

Row by row

~20 min

Quick check

What does SUMX ( Sales, Sales[Qty] * Sales[Unit Price] ) do?

Go deeper

  1. 1Calculate revenue with SUMX instead of a calculated column.
  2. 2Use AVERAGEX over VALUES ( Customer[CustomerID] ) to find average sales per customer.
  3. 3Learn that iterators create row context, which matters in the next phase.

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