Ancaster, Ontario
Posts

Row Context, Iterators, and the Current Row

July 9, 2021
SUMX is not just a longer SUM. It iterates a table and evaluates an expression for each row before aggregating the results.
DAX
Gross Profit :=
SUMX ( Sales, Sales[Quantity] * Sales[UnitPrice] - Sales[Cost] )
Inside the iterator, the current row makes each column reference meaningful. Outside that iteration, a measure normally sees a filter context instead. Confusing the two often leads to formulas that work in one visual and fail in another. When a calculation repeats a grain such as order and line, identify that grain explicitly before writing the measure. If source rows can duplicate a line, SUMX over raw rows may faithfully multiply the problem. First define the intended set of rows, then calculate over it. SQLBI's row and filter context overview explains the distinction in depth.
On this page