How to Use SUM in DAX in Power BI: Simple Guide
In Power BI, use the
SUM function in DAX to add all numbers in a single column. The syntax is SUM(ColumnName), where ColumnName is the column you want to total. This function returns the sum of all values in that column for the current filter context.Syntax
The SUM function adds all numeric values in a specified column.
- SUM(ColumnName): Adds all numbers in
ColumnName. ColumnNamemust be a column with numeric data.- Returns a single number representing the total.
DAX
SUM(TableName[ColumnName])
Example
This example shows how to create a measure that sums the SalesAmount column in the Sales table.
DAX
Total Sales = SUM(Sales[SalesAmount])
Output
If Sales[SalesAmount] contains values: 100, 200, 300, the measure returns 600
Common Pitfalls
Common mistakes when using SUM include:
- Trying to sum a column with non-numeric data causes errors.
- Using
SUMon a calculated column that returns text will fail. - For multiple columns,
SUMworks only on one column at a time. - Confusing
SUMwithSUMX, which iterates over a table.
DAX
/* Wrong: summing text column */ Total Names = SUM(Customers[Name]) /* Right: sum numeric column */ Total Age = SUM(Customers[Age])
Quick Reference
| Function | Description | Example |
|---|---|---|
| SUM | Adds all numbers in a column | SUM(Sales[Amount]) |
| SUMX | Sums an expression over a table | SUMX(Sales, Sales[Quantity] * Sales[Price]) |
| AVERAGE | Calculates average of a column | AVERAGE(Sales[Amount]) |
| COUNT | Counts non-blank values | COUNT(Sales[OrderID]) |
Key Takeaways
Use SUM(ColumnName) to add all numeric values in a single column.
SUM works only on numeric columns, not text or mixed data.
SUM returns a single total number based on current filters.
For row-by-row calculations, consider SUMX instead of SUM.
Check data types to avoid errors when using SUM.