Sub topic 18
PivotTables, SUMPRODUCT, and other options
This chapter assumes you can write SUMIFS, COUNTIFS, and AVERAGEIFS formulas with several criteria pairs, and that you understand absolute and mixed references. It covers where those functions stop being the best choice and what to use instead.
The examples use the sales layout from earlier chapters: Date in column A, Region in B, Product in C, Amount in D, and Notes in E, with data in rows 2 to 100.
What the *IFS functions do well
The *IFS functions are the right default when you need one number for a fixed set of conditions. They are fast to write, easy to audit, and recalculate automatically when the data changes.
They struggle in four situations:
- You want a whole summary, such as totals for every region and product, and don't want to build the grid yourself.
- Your conditions need OR logic across different fields.
- Your criteria need a calculation on the data, such as "the month of the date is January".
- You need to treat the result as a list of rows, not a single number.
PivotTables for whole summaries
A PivotTable is a tool that groups rows and summarizes them for you. It replaces the region-by-product grid of mixed-reference SUMIFS formulas with a drag-and-drop layout.
- Click any cell in the data, or better, convert the data to a table named Sales first.
- Choose Insert, then PivotTable.
- Drag Region to Rows, Product to Columns, and Amount to Values.
Excel sums Amount by default. You can switch the value field to Count or Average, which matches the three functions you already know.
| Need | SUMIFS family | PivotTable |
|---|---|---|
| One number in a report cell | Best fit | Overkill |
| Full grid of totals | One copied formula | Fastest to build |
| Updates when data changes | Automatic | Manual: Refresh or Refresh All |
| Custom layout inside a larger sheet | Full control | Fixed pivot layout |
| Regroup by month or year | Needs date-range criteria | Built-in date grouping |
The refresh step is the usual source of confusion. A pivot is a snapshot, so new rows do not appear until you refresh it. If the source is a plain range, rows added below row 100 may be missed. Using a table as the source avoids that.
SUMPRODUCT for conditions the *IFS functions can't express
SUMPRODUCT multiplies arrays element by element and adds the results. A comparison such as B2:B100="West" produces an array of TRUE and FALSE values. Multiplying by 1 or by another array turns those into numbers. This lets you build conditions yourself.
The pattern is SUMPRODUCT((condition1)*(condition2)*values). Multiplication means AND, and addition means OR.
=SUMPRODUCT((B2:B100="West")*(C2:C100="Laptop")*D2:D100)This matches SUMIFS(D2:D100, B2:B100, "West", C2:C100, "Laptop"). It has no advantage for this case, so use SUMIFS here.
OR across different fields
SUMIFS can only add two results when the OR is within one field. For "West region OR Laptop product", the add-two-SUMIFS trick double counts rows that are both. SUMPRODUCT handles it by testing whether the sum of the conditions is greater than zero:
=SUMPRODUCT(((B2:B100="West")+(C2:C100="Laptop")>0)*D2:D100)A West laptop row gives 1+1=2, which is greater than 0, so it is counted once.
Calculated conditions
SUMIFS cannot apply a function such as MONTH to the criteria range. SUMPRODUCT can:
=SUMPRODUCT((MONTH(A2:A100)=1)*(A2:A100<>"")*D2:D100)The A2:A100<>"" test is needed. A blank cell is treated as 0, which Excel reads as a date in January 1900, so MONTH returns 1 for every empty row. Here the blank rows have no Amount, so the total would survive. A count built the same way would not.
Gotchas with SUMPRODUCT
- Text in the value range. Multiplying by a text value in column D gives #VALUE!. SUMIFS ignores text in the sum range.
- No wildcards. The
=operator compares exact text, soC2:C100="Lap*"matches nothing. UseLEFT(C2:C100,3)="Lap"orISNUMBER(SEARCH("Lap",C2:C100)). - Same-size arrays. SUMPRODUCT returns #VALUE! when the arrays differ in size. SUMIFS gives the same error for mismatched ranges.
- Speed. SUMPRODUCT works on whole arrays and calculates more slowly on large sheets, especially with many formulas.
FILTER with SUM for lists of matches
In Microsoft 365 and Excel 2021 or later, FILTER returns the rows that match a condition. Wrapping it in SUM gives a conditional total with the same logic as SUMPRODUCT, but it is easier to read:
=SUM(FILTER(D2:D100, (B2:B100="West")+(C2:C100="Laptop"), 0))The third argument is the value returned when nothing matches. Without it, FILTER returns a #CALC! error. FILTER is also the right tool when you want to see the matching rows, not just add them up. Older Excel versions do not have it.
Other functions worth knowing
- MAXIFS and MINIFS follow the same argument order as SUMIFS (value range first, then criteria pairs). Use them for the largest or smallest matching value.
- SUBTOTAL and AGGREGATE respond to filtered or hidden rows, which the *IFS functions do not. If you need the total of what is currently visible after applying a filter, use
SUBTOTAL(109, D2:D100). - DSUM, DCOUNT, and DAVERAGE read their conditions from a criteria block on the sheet. They are rarely needed now but still appear in older workbooks.
- Power Query is the better option when the data must be cleaned or combined from several files before any totals are computed.
Choosing a tool
As a rule of thumb:
- Start with the *IFS function. It is the easiest to read and check.
- Move to a PivotTable when the result is a table of many totals.
- Move to SUMPRODUCT or FILTER when you need OR across fields or a calculation on the criteria range.
- Move to Power Query when the problem is the shape of the data, not the formula.
Exercises
Exercise
You want the total Amount for rows where Region is "West" or Product is "Laptop", counting each row once. Why does adding two SUMIFS formulas give the wrong answer, and which formula is correct?
Show answer
Rows that are both West and Laptop are included in both SUMIFS results, so they are counted twice. Use =SUMPRODUCT(((B2:B100="West")+(C2:C100="Laptop")>0)*D2:D100). A row matching both conditions sums to 2, which is greater than 0, so it is included once.
Exercise
A colleague's PivotTable shows a West total of 1510, but =SUMIFS(D2:D100, B2:B100, "West") shows 1830. Give two likely causes and say how you would check each.
Show answer
First, the PivotTable may be stale because rows were added or changed after the last refresh. Refresh it and compare again. Second, the pivot's source range may not cover all of the data, for example if it stops before the new rows. Check the source range under PivotTable Analyze, then Change Data Source, or rebuild the pivot from the Sales table so that it grows with the data.