Skip to content

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.

  • Line-level math that must happen before summing: Qty × Price, Amount − Discount, unit margin × units.
  • Weighted totals and weighted averages (divide two SumX results with Divide).
GrossRevenue := SumX(Sales, Sales.Qty * Sales.Price)
// The classic weighted average
WeightedPrice := Divide(SumX(Sales, Sales.Qty * Sales.Price), Sum(Sales.Qty))

Row expressions compile to plain SQL inside the aggregate — no per-row loop, no context transition:

GrossRevenue := SumX(Sales, Sales.Qty * Sales.Price)
  • 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.