Module 3 · Power BI DAX
"Iterators: SUMX, AVERAGEX and friends"
Calculate row by row and then aggregate, choose the right "average of what", and use RELATED to bring values from a dimension into the loop.
About 25 minutes
The problem
The sales director asks a simple-sounding question: "What's our average sale?" Three analysts give three answers:
- ₦194,689: the average order line.
- ₦6.66m: the average customer in 2025.
- ₦44.98m: the average month in 2025.
All three are correct. They're averages of different things. An "average" in DAX is never just AVERAGE(column): you have to decide what you're averaging over, and that's what iterators let you say.
The concept
An iterator loops over a table, evaluates an expression for each row (in row context), then aggregates the results:
DAX
SUMX ( <table>, <expression> )| Iterator | Aggregates with |
|---|---|
SUMX | sum |
AVERAGEX | average, skipping blanks |
MINX, MAXX | smallest, largest |
COUNTX | count of non-blank results |
CONCATENATEX | joins text, such as a list of names |
SUM ( orders[quantity] ) is really shorthand for SUMX ( orders, orders[quantity] ).
The table you iterate decides the "average of what"
| Measure | Iterates over | Means |
|---|---|---|
AVERAGEX ( orders, … ) | order lines | average line value |
AVERAGEX ( VALUES ( orders[customer_id] ), [Revenue] ) | customers who bought | average revenue per customer |
AVERAGEX ( VALUES ( 'Date'[Year Month] ), [Revenue] ) | months | average monthly revenue |
VALUES ( column ) returns the distinct values of a column that are visible in the current filter context, so it's the natural thing to iterate when you want "per customer" or "per month".
When you iterate a list of customers and call [Revenue], context transition filters each customer in turn, which is exactly what lesson 2 explained. And because AVERAGEX skips blanks, months with no sales (such as July 2026, which hasn't happened) don't drag the average down.
RELATED inside an iterator
While iterating orders (the many side), RELATED ( products[list_price] ) fetches the matching value from the one side. That lets you compare what customers paid with the list price.
Example
DAX
Avg Line Value = AVERAGEX ( orders, orders[quantity] * orders[unit_price] * ( 1 - orders[discount_pct] / 100 ) )
Avg Revenue per Customer = AVERAGEX ( VALUES ( orders[customer_id] ), [Revenue] )
Avg Monthly Revenue = AVERAGEX ( VALUES ( 'Date'[Year Month] ), [Revenue] )
Best Month Revenue = MAXX ( VALUES ( 'Date'[Year Month] ), [Revenue] )
Revenue at List Price = SUMX ( orders, orders[quantity] * RELATED ( products[list_price] ) )
Below List % = 1 - DIVIDE ( [Revenue], [Revenue at List Price] )Best Month Revenue shows ₦66.3m across all dates: December 2025, the festive peak. In a matrix by year, it shows each year's best month instead, because VALUES ( 'Date'[Year Month] ) only returns the months in that year's filter context.
Walkthrough
- Add the six measures to
_Measuresand format them. - Build a table with
Date[Year]andAvg Line Value,Avg Revenue per CustomerandAvg Monthly Revenue. The three "averages" differ by factors of about 30 and 200. - Replace
VALUES ( orders[customer_id] )withVALUES ( customers[customer_id] )and compare the 2025 figure. It's the same, because[Revenue]is blank for the nine customers who didn't buy in 2025 andAVERAGEXskips them. Now try[Revenue] + 0inside theAVERAGEX: the zeros count, and the average falls. Decide which you mean, and write it deliberately. - Put
Below List %in a table byDate[Year]. In 2026 it's just the discount; in 2025 it's much bigger. The difference is the January 2026 price rise: 2025 sales were at the old prices.
Practice
Practice
What is Avg Revenue per Customer in 2025? (A rounded figure is fine.)
Practice
In 2025, how far below today's list prices was Revenue? Give Below List % to one decimal place.
Task
4 minWrite a measure Avg Units per Customer: the average number of units (packs) bought per customer who ordered, in the current filter context. Paste it here.
Your work is checked for
- Named Avg Units per Customer
- Uses AVERAGEX, or DIVIDE of units by customers
- Works per customer: iterates customer_id values or divides by a customer count
Challenge
Challenge · optional
What is Best Month Revenue in 2026 (January to June)? (A rounded figure is fine.)
More practice
Drill · optional
What is Avg Line Value across all dates? Round to the nearest naira.
Drill · optional
Legal data: write Avg Invoice per Matter = AVERAGEX(VALUES(invoices[matter_id]), CALCULATE(SUM(invoices[amount_ngn]))). What is it across all invoices? Round to the nearest naira.
Check your understanding
Answer every question to check.