The SUBTOTAL function adds up (or averages, counts, or finds the max of) a range while automatically ignoring rows that a filter has hidden. The classic example is a sales table where you filter by region and want the total to show only the filtered rows: use =SUBTOTAL(9,C2:C100) instead of =SUM(C2:C100), and the total updates the moment you change the filter. Anything you need first is built in — SUBTOTAL ships with every current version of Excel and also works in Google Sheets and Excel for the web, so no add-in is required.
How SUBTOTAL Differs From SUM
The first argument of SUBTOTAL is a function number that tells Excel which calculation to run, and the second is the range. The most important numbers are 9 (SUM), 1 (AVERAGE), 2 (COUNT), 3 (COUNTA), 4 (MAX) and 5 (MIN). As a rule of thumb, filters set through Data > Filter are respected, while rows you simply hide yourself are not, unless you use the 100-series numbers. That distinction is the whole trick, and it is the source of most confusion, so pick the series deliberately.
What You'll Need
- Excel (Microsoft 365, Excel 2019 or later, or Excel for the web), Google Sheets or another spreadsheet app that supports SUBTOTAL. Menu labels can differ slightly by version, device and region.
- A data range with a single header row, no blank rows or columns inside it, and one column of numbers you want to total.
- A column you will filter on (region, month, category, salesperson) so you can see the function react.
- A free empty cell below or beside the table for the formula, ideally with a label like “Visible total” next to it.
Step-by-Step
- Lay the data out cleanly. Put headers in row 1 (Region, Salesperson, Sales) and data from row 2 down. Delete any blank rows or fully blank columns inside the block, because SUBTOTAL and filters both stop at the first empty gap.
- Turn the range into a filterable table. Select any cell inside the data and go to Data > Filter. A dropdown arrow appears on each header. On mobile Excel and in Excel for the web the same command sits in the Data tab; on some versions it is under Home > Sort & Filter > Filter. Either way, confirm the arrows appear before continuing.
- Write the SUBTOTAL formula in the total cell. If your Sales numbers are in C2:C100, type
=SUBTOTAL(9,C2:C100)and press Enter. The 9 tells Excel to sum. The result should match a plain=SUM(C2:C100)while nothing is filtered — that is a quick sanity check that your range is right. - Test it with a filter. Click the Region header arrow, untick “Select All”, tick one region and click OK. The total cell should drop to the sum of just that region. Clear the filter and it returns to the full total. If the number does not move, you almost certainly used SUM instead of SUBTOTAL.
- Switch the calculation without rewriting much. Change the first argument to get a different measure on the visible rows:
=SUBTOTAL(1,C2:C100)for the average,2for count of numbers,3for count of non-empty cells,4for the highest value and5for the lowest. - Choose the 100-series if you hide rows manually. Formula numbers 101–111 do the same jobs but also ignore rows you hide by right-clicking and choosing Hide. Use
=SUBTOTAL(109,C2:C100)when you want a total of only the rows currently visible for any reason. - Fill the formula across columns if needed. Drag the fill handle right to apply the same SUBTOTAL pattern to other numeric columns. Keep the range absolute (C$2:C$100) if the formula will be copied down as well as across.
- Add a second SUBTOTAL for a different measure. Put a SUM version in one cell and an AVERAGE version two rows below it. Leave a blank row between them, because stacked subtotal formulas that touch each other can be counted twice.
Common Mistakes
- Using SUM and expecting a filtered result. SUM totals hidden-by-filter rows too. That is the single most common error.
- Mixing 1–9 and 101–111 in one column. If one total ignores manually hidden rows and the one below it does not, the numbers will not reconcile and you will chase a phantom discrepancy.
- Including the total row in the range. If you place the formula in C101 and sum C2:C101, Excel flags a circular reference or double-counts. Always stop the range one row above the total.
- Wrapping SUBTOTAL in SUM.
=SUM(SUBTOTAL(9,C2:C10))adds double work and often produces wrong results when ranges overlap. - Nesting SUBTOTAL inside SUBTOTAL over the same cells. Excel deliberately ignores nested SUBTOTAL results inside a parent SUBTOTAL, so the outer total can come out lower than expected.
- Filtering with checkboxes in a helper column instead of the real filter. Those rows are not “hidden” in the sense SUBTOTAL understands, so the total stays unchanged.
Tips
- Give the total cell a label such as “Visible sales” so nobody later “fixes” it back to SUM.
- Use SUBTOTAL inside a table (Insert > Table) as well — structured references like
=SUBTOTAL(9,Table1[Sales])read cleanly and expand automatically. - Grand totals of a column of SUBTOTALs should use
=SUBTOTAL(9,range)too, since it will not double-count the subtotal cells above it. - For a single quick glance rather than a permanent formula, select the numbers and check the status bar at the bottom of the window — it shows Sum, Average and Count for the selection and respects filters.
- Prefer the 100-series when your colleagues hide rows by hand rather than filtering, which is common in shared review workbooks.
Troubleshooting
The total doesn’t change when I filter. Check the first argument — if it is 9 and not 109, manual hides will still count, but proper filters should still update. If nothing moves at all, confirm the formula is SUBTOTAL and not SUM, and that the filter is applied through Data > Filter on the same block.
I get #VALUE! or a strange number. Look for text or error values inside the range, or a stray header row included in the sum. Click the red error marker if one appears and read the suggested cause.
The number is double what I expect. Your range probably includes another subtotal row or a duplicated block of data. Sort the range and scan for repeated rows.
It works but shows the wrong figure after sorting. SUBTOTAL recalculates after sorting, so a wrong result usually means the range does not cover every data row. Extend it to the last row of data.
If that did not work, delete the formula, retype it by hand (pasting from another file can bring odd formats), and press Enter. Then clear all filters, verify the plain SUM matches, and reapply the filter one column at a time to find the culprit. As a last resort, save a copy and rebuild the data as a table.
Frequently Asked Questions
Why use SUBTOTAL instead of SUM?
Because SUBTOTAL respects filters and, with the 100-series numbers, manual row hides, so a filtered view always shows a total for what you can actually see. SUM totals everything in the range regardless.
What does the 9 mean in SUBTOTAL?
It is the function number for SUM. Use 109 for a sum that also ignores rows you hid manually, 1 or 101 for an average, and 2 or 102 to count numeric cells.
Does SUBTOTAL ignore hidden rows?
Rows hidden by a filter, yes, for any function number. Rows you hide yourself only count as hidden when you use 101–111.
Can I use SUBTOTAL in Google Sheets?
Yes. Google Sheets supports SUBTOTAL with the same function numbers, and it ignores rows hidden by its own filter views and normal filters.
Does SUBTOTAL ignore errors in the range?
No. An error value such as #DIV/0! in the range will break the total. Unlike AGGREGATE, SUBTOTAL has no option to skip errors, so clean them up or switch to AGGREGATE if you need that behaviour.
Why does my SUBTOTAL show zero?
Usually the range points at text-formatted numbers, or at an empty range, or every row in it is filtered out. Check that the cells are true numbers by selecting one and reading the status bar.