0
0
Power-biHow-ToBeginner ยท 3 min read

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 SUMX without a proper table, causing errors.
  • Confusing SUMX with SUM, 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

PartDescription
TableThe table to iterate over row by row
ExpressionThe calculation performed on each row
ResultSum 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.