Iterator Functions

SUM vs SUMX

Use a real order-lines scenario to see the difference between adding an existing column and iterating row by row to calculate an expression. This is the gateway to understanding all the DAX X functions.

Core Difference

SUM(OrderLines[NetAmount])

Use SUM when the value already exists as a column.

SUMX(OrderLines, OrderLines[Qty] * OrderLines[UnitPrice] * (1 - OrderLines[DiscountPct]))

Use SUMX when DAX must compute something for each row before adding it up.

Order Lines

Green row = current SUMX iteration
Order Product Qty Unit Price Discount Net Amount

Result Comparison

Same filter context, different logic

SUM of existing column

$0

Best when the table already stores a reusable numeric column like NetAmount.

SUMX of row expression

$0

Best when the amount must be computed per row using quantity, price, discount, tax, margin, or exchange rate.

Common wrong shortcut

$0

SUM(Qty) * AVERAGE(UnitPrice) * (1 - AVERAGE(Discount)) can look convenient but often gives the wrong business result.

When to use which

And why X functions matter

Use SUM when

  • The value you want to add already exists in one physical column.
  • You want the simplest and fastest expression.
  • Examples: Sales[Amount], GL[Debit], Inventory[OnHandQty].
Total Net Amount := SUM(OrderLines[NetAmount])

Use SUMX when

  • The amount must be calculated row by row first.
  • The expression uses more than one column from the same row.
  • Examples: quantity × price, amount × exchange rate, revenue - cost, weighted scoring.
Total Net Amount := SUMX( OrderLines, OrderLines[Qty] * OrderLines[UnitPrice] * (1 - OrderLines[DiscountPct]) )

Real-life examples of X functions

  • SUMX: invoice lines, variable pricing, tax, margin, freight.
  • AVERAGEX: average customer profitability per customer.
  • MAXX/MINX: highest or lowest row-based computed value.
  • CONCATENATEX: combine text from visible rows in a report.

Important nuance

  • SUM is not “bad”. If the correct result already exists as a column, SUM is the right tool.
  • SUMX is not automatically better. It is needed only when the calculation must be evaluated for each row.
  • If you can model a reusable helper column correctly, sometimes SUM becomes enough.
Rule of thumb: if your business question sounds like “for each row, calculate something, then total it”, you probably need an X function. If it sounds like “just add the values already stored in this column”, plain SUM is enough.