DAX SUMX function

Calculates an expression for each row of a table, then adds the results.

SUMX is SUM's row-by-row version. Use it when the number you want to add doesn't exist as a column yet, like units × price.

Syntax

SUMX(<table>, <expression>)
ArgumentRequiredDescription
tableRequiredThe table to go through, one row at a time.
expressionRequiredThe calculation for each row. It can use the columns of that row.

Returns: A decimal number.

Examples

Calculated on the free practice data (table financials), with [Total Sales] = SUM(financials[Sales]) and [Total Profit] = SUM(financials[Profit]).

1. Gross sales (before discounts) by product

Gross Sales = SUMX(financials, financials[Units Sold] * financials[Sale Price])
ProductGross Sales
Amarilla19,037,279.50
Carretera14,937,520.50
Montana16,549,834.50
Paseo35,611,662
Velo19,826,768.50
VTT21,968,533.50
Total127,931,598.50

Units times list price for every row, then added. It is higher than Sales because Sales is after discounts.

Good to know

  • SUMX over a big fact table is fine; SUMX with a measure inside runs CALCULATE once per row, which can be slow.
  • To sum a measure per group, iterate the groups: SUMX(VALUES(financials[Country]), [Some Measure]).

Related functions

Official reference: SUMX function on Microsoft Learn