Average sales per customer with AVERAGEX
Iterate the Customer table and average a measure — and see why context transition makes it work.
You will learn to
- Average a measure over a dimension table with AVERAGEX
- Explain context transition
- Spot the SUM-inside-an-iterator mistake
How it works
`AVERAGEX(table, expression)` works out the expression for every row of a table, then averages the results. Iterate `Customer` and you get one value per customer.
Here is the key idea. When a **measure** such as `[Total Sales]` is evaluated inside an iterator, DAX turns the current row into a filter. This is called **context transition**: on Avery’s row, `[Total Sales]` means Avery’s sales.
A plain column aggregation does not do that. `SUM(Sales[Amount])` inside the same iterator ignores which customer you are on and returns the total for the whole cell, every time.
Blank results are skipped by `AVERAGEX`, so customers who bought nothing in the current context don’t drag the average down.
Practice it hands-on with a real data model and a live report that updates as you type.
Avg Sales per Product = AVERAGEX(Product, [Total Sales])