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>)| Argument | Required | Description |
|---|---|---|
| table | Required | The table to go through, one row at a time. |
| expression | Required | The 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])| Product | Gross Sales |
|---|---|
| Amarilla | 19,037,279.50 |
| Carretera | 14,937,520.50 |
| Montana | 16,549,834.50 |
| Paseo | 35,611,662 |
| Velo | 19,826,768.50 |
| VTT | 21,968,533.50 |
| Total | 127,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