SumX
Iterator
SumX(table, rowExpr)
The sanctioned door into row context: evaluates rowExpr for each row of the named table, then sums. Bare columns of the iterated table are legal inside the row expression — and only there. Aggregations, measure references, and context/time functions cannot appear per-row (SQX009/SQX014).
SumX is additive, so it composes under YTD/QTD/MTD and RollingSum.
When to use it
Section titled “When to use it”- Line-level math that must happen before summing:
Qty × Price,Amount − Discount, unit margin × units. - Weighted totals and weighted averages (divide two
SumXresults withDivide).
Example
Section titled “Example”GrossRevenue := SumX(Sales, Sales.Qty * Sales.Price)
// The classic weighted averageWeightedPrice := Divide(SumX(Sales, Sales.Qty * Sales.Price), Sum(Sales.Qty))Under the hood
Section titled “Under the hood”Row expressions compile to plain SQL inside the aggregate — no per-row loop, no context transition:
GrossRevenue := SumX(Sales, Sales.Qty * Sales.Price)SELECT "Sales"."region", SUM("Sales"."qty" * "Sales"."price") AS "GrossRevenue"FROM "sales" AS "Sales"GROUP BY "Sales"."region"Good to know
Section titled “Good to know”- Row expressions reference the ITERATED table only — a column from another table is SQX014 (name that table as the iterator instead).
- No context transition:
[Measure]references are rejected per-row — reference the columns directly.