How to use SUM and SUMX in DAX (Power BI)

Understanding SUM and SUMX in DAX for Power BI

Power BI users frequently need to perform aggregations, and two popular functions for summation in DAX are SUM and SUMX. Although they appear similar, they have different uses based on the situation. In this blog, we’ll look at the differences between SUM and SUMX with practical examples.

What is the SUM Function in DAX?

The SUM function is an easy way to add all the values in a column.

Syntax:

SUM(<column>)

Example:

Consider a sales table with the following structure:

ProductSalesAmount
A100
B200
C150

To calculate the total sales, use:

Total Sales = SUM(Sales[SalesAmount])

This will return 100 + 200 + 150 = 450.

Create Sum Measure as:

What is the SUMX Function in DAX?

The SUMX function is an iterator function that evaluates an expression row by row and then sums the results.

Syntax:

SUMX(<table>, <expression>)

Example:

Consider a sales table with additional quantity and price columns:

ProductQuantityPrice
A250
B380
C530

If you need to calculate the total revenue (Quantity * Price), using SUM won’t work because it operates on a single column. Instead, use SUMX:

Total Revenue = SUMX(Sales, Sales[Quantity] * Sales[Price])

This will calculate:

  • (2 * 50) + (3 * 80) + (5 * 30) = 100 + 240 + 150 = 490

Create sumx measure as

Key Differences Between SUM and SUMX

FeatureSUMSUMX
Works onA single columnAn expression across multiple columns
IterationNo iterationIterates row by row
Use caseSimple aggregationsCalculated aggregations (multiplication, conditional sums, etc.)

When to Use SUM vs. SUMX

  • Use SUM when you simply need to aggregate a column of numbers.
  • Use SUMX when calculations are needed on multiple columns before summation.

This entry was posted in Oracle on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply