SUM vs SUMX in Power BI — When to Use Which
SUM adds one numeric column under the current filter context. SUMX walks a table row by row, evaluates an expression for each row (row context), then adds those results. Use SUM when the column already exists. Use SUMX when you must calculate per row first.
Friends! SUM looks small, SUMX looks scary, and interviews love the difference. Why? Because Qty × Price is everywhere in business data. How? We compare both on the same FreshBasket lines. Tiny example, then rules of thumb, then mistakes. Let’s make it crystal clear.
मित्रांनो! SUM looks small, SUMX looks scary, and interviews love the difference. Why? Because Qty × Price is everywhere in business data. How? We compare both on the same FreshBasket lines. Tiny example, then rules of thumb, then mistakes. एकदम clear करूया.
मित्रों! SUM looks small, SUMX looks scary, and interviews love the difference. Why? Because Qty × Price is everywhere in business data. How? We compare both on the same FreshBasket lines. Tiny example, then rules of thumb, then mistakes. एकदम clear करते हैं.
Quick answer
Vertical chooser:
- Have
Amountready? →Total = SUM ( Sales[Amount] ). - Only
QtyandUnitPrice? →Total = SUMX ( Sales, Sales[Qty] * Sales[UnitPrice] ). - SUM expects a column reference, not a free expression.
- SUMX is an iterator (row context inside the expression).
- Prefer SUM when possible — simpler and often faster.
- Keep SUMX expressions lean on large tables.
SUM ( table[column] )
SUMX ( table, <row expression> )
What do I need before this guide?
- Basic measures (DAX beginner).
- Optional: filter context comfort (CALCULATE guide).
- Course: Aggregation functions.
Before and after (look at the tables first)
Before
आधी (Before)
पहले (Before)
After
नंतर (After)
बाद में (After)
SUM needs Amount ready. SUMX walks each row (Qty * UnitPrice) then adds — here 140. Prefer SUM when Amount already exists.
Why two functions exist (and why you care)
Business files arrive in two shapes:
- Already extended: each row has Amount.
- Need a line total: Qty and UnitPrice must multiply before totalling.
Why you care:
- Interviews ask “when SUMX?” — answer with Qty × Price.
- Using the wrong one either errors or gives a wrong total.
- Prefer SUM when Amount already exists — simpler and often faster.
Tiny classroom table (Mumbai and Pune style):
| City | Qty | UnitPrice | Amount |
|---|---|---|---|
| Mumbai | 2 | 50 | 100 |
| Pune | 1 | 40 | 40 |
SUM totals one numeric column; SUMX walks a table and totals a per-row expression.
मित्रांनो — SUM totals one numeric column; SUMX walks a table and totals a per-row expression.
मित्रों — SUM totals one numeric column; SUMX walks a table and totals a per-row expression.
SUM in depth — WHY, WHAT happens, what you see
Why use SUM
- The number you need already sits in one column (
Amount). - You only need to add that column under the current filters.
- You do not need a per-row multiply first.
Pattern
Total Amount =
SUM ( Sales[Amount] )
What Power BI does to the rows (step by step)
- Look at Sales under current filter context.
- No slicer: both rows visible.
- Take Amount values: 100 and 40.
- Add them → 140.
- Return 140 to the visual.
- City slicer = Mumbai → only Amount 100 remains → result 100.
What you see on screen
- Card shows 140.
- After Mumbai slicer → 100.
Good fits
- Revenue column already correct.
- Quantity column summed for “units sold”.
- Any additive fact you trust.
What SUM will not do
SUM ( Sales[Qty] * Sales[UnitPrice] )— not valid like Excel array dreams; use SUMX or a column.
SUMX in depth — WHY, WHAT happens, what you see
SUMX creates row context: for each Sales row compute Qty × Price, then add those results.
SUMX row context तयार करतो: for each Sales row compute Qty × Price, then add those results.
मित्रों — SUMX creates row context: for each Sales row compute Qty × Price, then add those results.
Why use SUMX
- You do not have a ready Amount column — only Qty and UnitPrice.
- Or you must apply a per-row rule (discount, IF) before totalling.
- SUM cannot take a free expression like Qty * UnitPrice.
Why you need the table argument (the “helper” beside the expression)
- SUMX’s first argument is the table to walk (usually
Sales). - The second argument is the expression per row.
- Without the table, Power BI would not know which rows to visit one by one.
- That walk creates row context (the current row while the expression runs).
Pattern
Total Line Sales =
SUMX (
Sales,
Sales[Qty] * Sales[UnitPrice]
)
What Power BI does to the rows (step by step)
- Start with Sales rows that survive filter context.
- Row 1 (Mumbai): Qty 2 × UnitPrice 50 → line 100. Keep it.
- Row 2 (Pune): Qty 1 × UnitPrice 40 → line 40. Keep it.
- After the loop, sum those line results → 140.
- City slicer = Mumbai → only row 1 is walked → 100.
That loop is why people say “iterator”.
What you see on screen
- Card with
[Total Line Sales]shows 140 (same as SUM on Amount when Amount is correct). - Mumbai slicer → 100.
Other SUMX ideas (still simple)
Total Discounted =
SUMX (
Sales,
Sales[Amount] * ( 1 - Sales[DiscountPct] )
)
If DiscountPct is blank sometimes, guard with IF — later practice.
Side-by-side classroom table
Pick SUM when Amount already exists; pick SUMX when you must multiply or use IF per row before totalling.
Amount आधीच असेल तेव्हा SUM निवडा; row वर multiply किंवा IF हवे असेल तेव्हा SUMX निवडा, मग total करा.
Amount पहले से हो तो SUM चुनो; row पर multiply या IF चाहिए तो SUMX चुनो, फिर total करो.
| Row | City | Qty | UnitPrice | Amount | Line (Qty×Price) |
|---|---|---|---|---|---|
| 1 | Mumbai | 2 | 50 | 100 | 100 |
| 2 | Pune | 1 | 40 | 40 | 40 |
| Total | SUM → 140 | SUMX → 140 |
If Amount always equals Qty×Price, both totals match. If someone edited Amount by hand in Excel, they might diverge — data quality topic.
Row context vs filter context (beginner bridge)
- Filter context — which rows are visible to the measure (slicers, etc.). Mumbai slicer → only Mumbai rows.
- Row context — the current row while an iterator (or calculated column) runs.
- SUMX creates row context for its expression.
- CALCULATE can turn row context into filter context in advanced patterns (course territory) — you do not need that on day one of SUMX.
Performance and modelling intuition
- A thin SUM over a clean column is hard to beat.
- SUMX that calls heavy nested CALCULATE per row on millions of rows can hurt.
- Sometimes adding
LineAmountin Power Query and then SUM is the calm enterprise pattern. - Choose consciously: Query column vs SUMX measure — both valid.
Mistakes checklist
| Mistake | Better approach |
|---|---|
| Forcing everything through SUMX | Use SUM for plain columns |
| SUM of an expression | SUMX or precompute column |
| SUMX over the wrong table | Iterate the fact table that holds Qty/Price |
| Ignoring filter context | Remember slicers still limit which rows are iterated |
| Copy-pasting giant SUMX from forums | Write the multiply yourself first |
Ravindra Bagale's Tip
Interview trap: "Is SUMX always better?" Answer: "No — SUMX when I need a row expression; SUM when the column exists." Short, confident, correct. Got it?
Ravindra Bagale's Tip – मराठी
Interview trap: "SUMX नेहमीच better आहे का?" उत्तर: "नाही — row expression हवी असेल तर SUMX; column अस्तित्वात असेल तर SUM." Short, confident, correct. समजलं का?
Ravindra Bagale's Tip – हिंदी
Interview trap: "क्या SUMX हमेशा better है?" जवाब: "नहीं — row expression चाहिए तो SUMX; column मौजूद हो तो SUM." Short, confident, correct. समझ में आया?
Lab
- Add Qty and UnitPrice if missing (Enter data is fine: Mumbai 2×50, Pune 1×40).
- Create
[Sum Amount]and[Sumx Line]. - Prove equality when Amount = QtyPrice (both 140*).
- Break one Amount on purpose; observe divergence.
- Decide whether you would fix in Query or keep SUMX.
Learn it properly
Course lessons:
- Aggregation functions
- Evaluation context
- Variables — VAR and RETURN
- Base measures for the quick commerce model
Related guides: Measures vs columns · CALCULATE
Optional: add a LineAmount column in Power Query instead
- Transform data → custom column
Qty * UnitPrice. - Set Decimal type.
- Close & Apply.
SUM ( Sales[LineAmount] ).
When teams standardise LineAmount in Query, analysts share one definition. SUMX remains perfect for flexible measures and prototypes.
Iterator family peek
SUMX is one of several iterators (AVERAGEX, COUNTX, …). Same idea: X ≈ “expression per row, then aggregate”. Learn SUMX first.
Got it? SUM totals a column; SUMX totals a per-row expression. Prefer SUM when you can. Next: build a first dashboard. Let’s continue.
समजलं का? SUM totals a column; SUMX totals a per-row expression. Prefer SUM when you can. Next: build a first dashboard. आता पुढे जाऊया.
समझ में आया? SUM totals a column; SUMX totals a per-row expression. Prefer SUM when you can. Next: build a first dashboard. आगे बढ़ते हैं.
Frequently asked questions
What is SUM?
An aggregation that adds all values in a single numeric column under the current filter context.
What is SUMX?
An iterator: it goes row by row over a table, evaluates an expression, then sums the results.
What is row context?
The “current row” while an iterator (or a calculated column) is evaluating — different from filter context.
Can SUM take an expression?
SUM expects a column reference. For expressions, use SUMX (or add a column first).
Is SUMX always better?
No. Use it when you need a per-row expression. Otherwise SUM is clearer.
Related learning?
Aggregation functions and evaluation context in the DAX course chapter.