0
0
Power-biComparisonBeginner · 3 min read

SUMX vs SUM in DAX: Key Differences and When to Use Each

In DAX, SUM adds all values in a single column directly, while SUMX iterates over a table, evaluates an expression for each row, then sums the results. Use SUM for simple column totals and SUMX when you need row-by-row calculations before summing.
⚖️

Quick Comparison

Here is a quick side-by-side comparison of SUM and SUMX functions in DAX.

FactorSUMSUMX
TypeAggregation functionIterator function
InputSingle columnTable and expression
OperationAdds column values directlyEvaluates expression row-by-row then sums
PerformanceFaster for simple sumsSlower due to row iteration
Use caseSimple total of a columnComplex calculations per row before summing
ExampleTotal sales amountTotal of (Quantity * Price) per row
⚖️

Key Differences

SUM is a straightforward aggregation function that adds all the numbers in a single column. It is simple and efficient when you just need the total of one column without any additional calculations.

SUMX, on the other hand, is an iterator function. It goes through each row of a table, calculates an expression for that row, and then sums all those calculated values. This makes SUMX more flexible for scenarios where you need to multiply, filter, or perform other calculations on each row before adding.

Because SUMX evaluates an expression row-by-row, it can be slower than SUM on large datasets. However, it is essential when your total depends on a calculation involving multiple columns or conditions.

⚖️

Code Comparison

Example: Calculate total sales amount from a column named Sales[Amount].

DAX
Total Sales = SUM(Sales[Amount])
Output
Returns the sum of all values in Sales[Amount]
↔️

SUMX Equivalent

Example: Calculate total sales by multiplying Quantity and Price columns row-by-row, then summing the results.

DAX
Total Sales = SUMX(Sales, Sales[Quantity] * Sales[Price])
Output
Returns the sum of Quantity * Price for each row in Sales
🎯

When to Use Which

Choose SUM when you need a simple total of a single column without any extra calculations. It is faster and easier to use for straightforward sums.

Choose SUMX when your total depends on calculations involving multiple columns or conditions per row, such as multiplying quantity by price or applying filters before summing. It offers flexibility at the cost of performance.

Key Takeaways

SUM adds values directly from one column and is best for simple totals.
SUMX iterates row-by-row to calculate expressions before summing, useful for complex calculations.
Use SUM for performance when no row-level calculation is needed.
Use SUMX when totals depend on multiple columns or expressions per row.
Understanding when to use each improves report accuracy and efficiency.