How to Use SUMX in DAX in Power BI: Simple Guide
Use
SUMX in DAX to sum values by evaluating an expression for each row in a table and then adding those results. It works like a loop that calculates a value per row before summing, useful for complex calculations in Power BI.Syntax
The SUMX function has two parts: a table and an expression. It goes through each row of the table, calculates the expression for that row, then adds all those results together.
- Table: The table or table expression to iterate over.
- Expression: The calculation to perform on each row.
DAX
SUMX(<Table>, <Expression>)
Example
This example shows how to calculate total sales amount by multiplying quantity and price for each row, then summing all results.
DAX
Total Sales = SUMX(Sales, Sales[Quantity] * Sales[Price])
Output
If Sales table has rows with Quantity=2, Price=10 and Quantity=3, Price=15, Total Sales = (2*10) + (3*15) = 65
Common Pitfalls
Common mistakes include:
- Using
SUMXwithout a proper table, causing errors. - Confusing
SUMXwithSUM, which sums a single column directly without row-by-row calculation. - Writing expressions that do not return a number for each row.
Always ensure the expression returns a numeric value for each row in the table.
DAX
/* Wrong: Using SUMX without table */ Total = SUMX(Sales[Quantity] * Sales[Price]) /* Correct: Provide table and expression */ Total = SUMX(Sales, Sales[Quantity] * Sales[Price])
Quick Reference
| Part | Description |
|---|---|
| Table | The table to iterate over row by row |
| Expression | The calculation performed on each row |
| Result | Sum of all expression results for each row |
Key Takeaways
SUMX sums values by evaluating an expression for each row in a table.
Always provide a table and a numeric expression to SUMX.
Use SUMX when you need row-by-row calculations before summing.
SUMX is different from SUM, which sums a single column directly.
Check your expression returns numbers to avoid errors.