What Is Difference Between Sum And Sumx In Dax

5 min read

Understanding the distinction between SUM and SUMX in DAX is essential for anyone building data models in Power BI, Analysis Services, or Power Pivot. Think about it: both functions aggregate numeric values, but they operate in fundamentally different ways, and choosing the wrong one can lead to incorrect results or unnecessary performance overhead. This guide explains what each function does, highlights the key differences, shows practical examples, and offers tips on when to use each one.


What is SUM in DAX?

SUM is a simple aggregation function that adds up all the values in a single column. Its syntax is:

SUM (  )
  • <column> must be a reference to a column that contains numeric data.
  • The function works in the current filter context; it respects any slicers, row‑level security, or visual filters applied to the model.
  • Because SUM operates on a column directly, the VertiPaq engine can scan the column’s compressed storage and return the total very quickly.

When to use SUM

  • You need a total of a raw column (e.g., total sales amount, total quantity).
  • No row‑by‑row calculation is required before aggregation.
  • Performance is a priority and the column already holds the final numeric value you want to sum.

Example

Total Sales = SUM ( Sales[SalesAmount] )

This measure returns the sum of every value in the SalesAmount column, filtered by whatever context the visual provides (date range, product category, etc.).


What is SUMX in DAX?

SUMX is an iterator function. It evaluates an expression for each row of a table and then adds up the results. Its syntax is:

SUMX ( ,  )

  • <table> can be any table expression: a physical table, a filtered version of a table (FILTER, ALL, etc.), or the result of another function.
  • <expression> is a DAX formula that is evaluated row‑by‑row for each row in <table>. The expression can reference columns from that table, use variables, or call other measures.
  • After the expression is calculated for every row, SUMX adds those intermediate values together.

When to use SUMX

  • You need to perform a calculation before summing (e.g., multiply price by quantity, apply a discount, or compute a margin).
  • The calculation depends on multiple columns or involves conditional logic that cannot be pre‑aggregated in a column.
  • You want to reuse a complex expression across different visuals without creating a calculated column.

Example

Total Revenue = 
SUMX (
    Sales,
    Sales[SalesAmount] * Sales[Quantity]   // expression evaluated per row
)

Here, for each row in the Sales table, DAX multiplies SalesAmount by Quantity and then sums all those products.


Core Differences Between SUM and SUMX

Aspect SUM SUMX
Function type Simple aggregation Iterator (row‑by‑row)
Input Single column reference Table expression + row‑level expression
Calculation timing Aggregates stored values directly Computes an expression for each row, then aggregates
Use case Summing a pre‑calculated column Summing the result of a calculation that varies per row
Performance Generally faster because VertiPaq can scan column storage Slightly slower due to row iteration; performance depends on table size and expression complexity
Context sensitivity Respects filters on the column only Respects filters on the table and any filters applied inside the expression
Return type Scalar (single number) Scalar (single number)

In short, SUM adds up what’s already there; SUMX adds up what you compute on the fly.


Practical Examples Showing the Difference

Example 1: Simple Total – Use SUM

Suppose you have a column Sales[NetAmount] that already contains the final sales value after discounts and taxes. To get the total net sales:

Total Net Sales = SUM ( Sales[NetAmount] )

Using SUMX here would be unnecessary and slower:

-- Not needed, but works
Total Net Sales (inefficient) = SUMX ( Sales, Sales[NetAmount] )

Both return the same number, but the first leverages the column store directly.

Example 2: Calculated Total – Use SUMX

Imagine you need total revenue, but your model stores UnitPrice and Quantity separately. The revenue per line is UnitPrice * Quantity. A calculated column could store this product, but that would increase model size And it works..

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

If you attempted to use SUM on a non‑existent “Revenue” column, you would get an error. SUMX lets you compute the revenue on the fly Easy to understand, harder to ignore..

Example 3: Conditional Aggregation – SUMX with FILTER

You want the total sales amount only for products in the “Electronics” category:

Electronics Sales = 
SUMX (
    FILTER ( Sales, RELATED ( Product[Category] ) = "Electronics" ),
    Sales[SalesAmount]
)

Here, FILTER creates a table of rows that meet the condition, and SUMX adds the SalesAmount for those rows. You could also achieve this with CALCULATE ( SUM ( Sales[SalesAmount] ), Product[Category] = "Electronics" ), but SUMX makes the row‑by‑row intent explicit.


Performance Considerations

Why SUM is Usually Faster

  • VertiPaq stores columns in a compressed, segment‑based format. SUM can read these segments directly and apply SIMD‑style vectorized addition.
  • No row context is created; the engine does not need to instantiate a row iterator for each record.

When SUMX May Be Acceptable

  • The table being iterated is relatively small (e.g., a dimension table with a few thousand rows) or heavily filtered beforehand.
  • The expression inside SUMX is simple (a few arithmetic operations) and benefits from VertiPaq’s fast column scans.
  • You avoid materializing a calculated column, saving storage space.

Tips to Optimize SUMX

  1. Reduce the iterator table – Apply FILTER, TOP N, or VALUES to limit rows before SUMX.
  2. Use variables – Store repeated sub‑expressions in variables to avoid recomputation.
    Total Cost = 
    VAR UnitCost = Sales[UnitCost]
    VAR Qty = Sales[Quantity]
    RETURN
    SUMX ( Sales, UnitCost * Qty )
    
  3. use existing measures – If a measure already encapsulates the row‑level logic, reference it inside SUMX to keep the code clean.
    Total Profit = SUMX ( Sales
New In

Recently Shared

You'll Probably Like These

Others Also Checked Out

Thank you for reading about What Is Difference Between Sum And Sumx In Dax. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home