SUBTOTAL and AGGREGATE: Totals That Ignore Hidden Rows and Errors
Zoya filters her sales list to Pune and the SUM at the bottom still shows the total for all cities. Then one cell shows #N/A from a lookup, and the whole total turns into #N/A. SUBTOTAL fixes the first problem and AGGREGATE fixes the second.
=SUBTOTAL(9,range) sums only the rows that are visible after a filter. =SUBTOTAL(109,range) also skips rows you hid by hand. =AGGREGATE(9,6,range) sums while ignoring error values, and option 7 ignores both hidden rows and errors.
Download the practice file (subtotal-aggregate.xlsx)
Excel file, 6 KB. It has the sample data used below. All numbers in this workbook are fictional teaching data, not real company figures.
Quick answer
- Filtered lists: use
=SUBTOTAL(9,C2:C9)instead of=SUM(C2:C9). - If you also hide rows by hand (right-click > Hide), use
=SUBTOTAL(109,C2:C9). - If the range may contain errors, use
=AGGREGATE(9,6,C2:C9). - For hidden rows and errors together:
=AGGREGATE(9,7,C2:C9). - In an Excel Table, the Total Row writes SUBTOTAL(109,...) for you.
=SUBTOTAL(9,C2:C9)
=SUBTOTAL(109,C2:C9)
=AGGREGATE(9,6,C2:C9)
Function numbers you need
| Job | SUBTOTAL (keeps hand-hidden rows) | SUBTOTAL (skips hand-hidden rows) | AGGREGATE |
|---|---|---|---|
| Sum | 9 | 109 | 9 |
| Count numbers | 2 | 102 | 2 |
| Count non-blank | 3 | 103 | 3 |
| Average | 1 | 101 | 1 |
| Max / Min | 4 / 5 | 104 / 105 | 4 / 5 |
Both SUBTOTAL versions always skip rows hidden by a filter. The only difference is rows hidden by hand.
The practice sheet
Rows 4 and 5 (Nashik) are hidden by hand, and Nagpur Aug (C7) holds an error, #N/A, from a lookup. The results:
| Formula | Result | Why |
|---|---|---|
=SUM(C2:C9) | #N/A | One error spoils SUM |
=AGGREGATE(9,6,C2:C9) | ₹6,61,000 | Ignores the error, counts hidden rows |
=AGGREGATE(9,7,C2:C9) | ₹4,88,000 | Ignores the error and the hidden Nashik rows |
=SUBTOTAL(109,D2:D9) | ₹4,88,000 | Column D is the same data with the error replaced by 0 |
=SUBTOTAL(9,D2:D9) | ₹6,61,000 | Code 9 keeps hand-hidden rows |
Where these help
- A total row above a filtered list that changes with the filter.
- Reports where you hide detail rows to show a summary.
- Data with a few lookup errors you cannot fix yet (better still: fix them with IFNA).
- Data > Subtotal (the feature) inserts SUBTOTAL(9,...) rows per group, and its Grand Total does not double count them.
Ravindra Bagale's Tip
Put the SUBTOTAL total above the header row of a filtered list, not below it. A total below the data can disappear when filters hide rows near the bottom, and it gets in the way when new rows are added.
Ravindra Bagale's Tip – मराठी
Filter केलेल्या list चा SUBTOTAL total header row च्या वर ठेवा, खाली नको. खाली ठेवलेला total filter मुळे लपू शकतो आणि नवीन rows टाकताना अडथळा येतो.
Ravindra Bagale's Tip – हिंदी
Filter की गई list का SUBTOTAL total header row के ऊपर रखिए, नीचे नहीं। नीचे वाला total filter से छिप सकता है और नई rows जोड़ते समय रुकावट बनता है।
Practice task
- Open the Sales sheet. Rows 4 and 5 are hidden; C7 shows #N/A.
- Check F2 (SUM) shows #N/A and F3 (AGGREGATE 9,6) shows a total.
- Unhide rows 4 and 5 (select rows 3 to 6, right-click > Unhide) and watch F4 and F5 change.
- Add a filter (Ctrl + Shift + L) and show only Pune. Check F5 changes.
- Replace C7's error with
=IFNA(NA(),0)and see SUM work again.
Learn it properly
Course lessons:
Related guides: IFERROR vs IFNA in Excel: Replace #N/A and #DIV/0! the Right Way · Excel Table vs Normal Range: When to Use Ctrl + T · Sort by Several Columns, Custom Sort Order and Advanced Filter · SUMIF and SUMIFS
Frequently asked questions
What is the difference between SUBTOTAL 9 and 109?
Both ignore rows hidden by a filter. 109 also ignores rows you hid manually; 9 still includes them.
Does SUBTOTAL ignore other SUBTOTALs?
Yes. SUBTOTAL skips cells that contain SUBTOTAL or AGGREGATE formulas, so group totals are not counted twice.
Which Excel versions have AGGREGATE?
Excel 2010 and later.
Can SUBTOTAL ignore errors?
No. Use AGGREGATE with option 6 or 7.