What an iterator is
An iterator takes a table, evaluates an expression for each row, then aggregates the results. SUMX, AVERAGEX, MAXX, RANKX, FILTER and ADDCOLUMNS all work this way.
The key difference from SUM: an iterator creates a row context, so it can reference columns of the current row.
Row context and context transition
Inside SUMX(Sales, Sales[Qty] * Sales[Price]), Sales[Qty] refers to the current row. That is row context.
If you wrap a measure inside an iterator, DAX performs context transition: the row context becomes a filter context. That is why SUMX(Sales, [Sales]) works but is usually slower than SUM.
FILTER versus filter arguments
Two ways to filter:
-- filter argument: fast, uses indexes where possible
CALCULATE( [Sales], Sales[Region] = "East" )
-- iterator: flexible, slower on large tables
CALCULATE( [Sales], FILTER( Sales, Sales[Region] = "East" ) )
Prefer the filter argument when a simple condition is enough. Use FILTER when the condition depends on a measure per row, or on multiple columns compared to each other.
RANKX and ties
Product Rank =
RANKX( ALL( Product[Name] ), [Sales],, DESC, DENSE )
DENSE gives consecutive ranks when values tie; SKIP leaves gaps like competition ranking. Choose deliberately: dense ranks are usually what business users expect.
Performance notes
- Iterators over fact tables are expensive; iterate dimensions where possible
- Push filtering to the filter argument instead of FILTER
- Avoid iterating a table you then aggregate with another iterator
A practical example
Average order value per customer:
Avg Order Value =
AVERAGEX(
VALUES( Sales[CustomerId] ),
CALCULATE( SUM( Sales[Amount] ) )
)
Here the iterator walks the distinct customers, and CALCULATE transitions each customer into a filter. That pattern appears constantly in cohort and ranking work.
Summary
Iterators give you row context, which is power and cost at the same time. Use them when the calculation truly needs a row, and use filter arguments when a condition is enough.