The SUBTOTAL formula in Excel is =SUBTOTAL(function_num, range1, [range2], ...). For example, =SUBTOTAL(9, A2:A10) returns the sum of values in A2:A10. This function is special because it can ignore rows hidden by filtering or manually hidden rows, depending on the function number you choose.
What the SUBTOTAL Function Actually Does
SUBTOTAL is a built-in Excel function that performs one of 11 operations (sum, average, count, max, min, etc.) on a range, but with a key twist: it can exclude rows that are hidden by a filter or hidden manually. This makes it the go-to tool for dynamic reports, dashboards, and data analysis where you want totals that update as you filter or hide data.
The function takes two or more arguments:
- function_num – a number from 1 to 11 (or 101 to 111) that tells Excel which operation to perform.
- range1, [range2], … – one or more ranges of cells to include. Up to 254 ranges are allowed.
For example, =SUBTOTAL(1, B2:B20) returns the average of B2:B20. The function number controls the operation.
Function Numbers: 1–11 vs. 101–111
The first argument determines both the operation and how hidden rows are treated. The numbers 1 through 11 ignore rows that are manually hidden (right-click > Hide). The numbers 101 through 111 ignore rows hidden by filtering (via AutoFilter or a slicer) as well as manually hidden rows. Here’s the full list:
- 1 / 101 – AVERAGE
- 2 / 102 – COUNT (numbers only)
- 3 / 103 – COUNTA (non-empty cells)
- 4 / 104 – MAX
- 5 / 105 – MIN
- 6 / 106 – PRODUCT
- 7 / 107 – STDEV (sample standard deviation)
- 8 / 108 – STDEVP (population standard deviation)
- 9 / 109 – SUM
- 10 / 110 – VAR (sample variance)
- 11 / 111 – VARP (population variance)
In practice, the most commonly used are 9 (sum) and 109 (sum that ignores filtered-out rows). For example, if you have a filter on column A that hides some rows, =SUBTOTAL(9, C2:C100) will still include those hidden rows, but =SUBTOTAL(109, C2:C100) will exclude them.
How to Use SUBTOTAL in a Real Spreadsheet
Suppose you have a sales table with amounts in B2:B10 and you want a total that updates when you filter by region. Place this in cell B11:
=SUBTOTAL(9, B2:B10)
This sums all values in B2:B10, ignoring any rows that are hidden manually. If you instead want the sum to respect an AutoFilter (e.g., filter to show only “East” region), use 109:
=SUBTOTAL(109, B2:B10)
Now, when you apply a filter to the table, the subtotal recalculates to show only the visible rows. This is the classic use for a “Total” row in a filtered table.
Common Problems and Misconceptions
One frequent mistake is using SUBTOTAL in a range that already contains other SUBTOTAL formulas. SUBTOTAL ignores other SUBTOTAL formulas in its range, which is actually a feature: it prevents double-counting in nested totals. For example, if you have subtotals at the bottom of each region and then a grand total using SUBTOTAL, the grand total only sums the data cells, not the region subtotals.
Another common issue: SUBTOTAL does not work with horizontal ranges the same way. If you apply it to a row of data, it works, but the hidden-row logic only applies to rows, not columns. There is no built-in way to ignore hidden columns with SUBTOTAL.
Also, users often confuse SUBTOTAL with the AGGREGATE function. AGGREGATE (available in Excel 2010 and later) is more powerful: it can ignore error values and hidden rows, and offers more functions (like LARGE, SMALL, PERCENTILE). But SUBTOTAL is simpler and sufficient for most filtering tasks.
SUBTOTAL vs. SUM: Which Should You Use?
The main difference is how they treat hidden rows. =SUM(A2:A10) always adds every cell in the range, regardless of filtering or hiding. =SUBTOTAL(9, A2:A10) adds all cells too, but if you use 109, it only adds visible rows. So:
- Use SUM when you always want the full total, no matter what is filtered or hidden.
- Use SUBTOTAL(109) when you want the total to reflect the current filter state, like in a dashboard or a report that users will filter.
- Use SUBTOTAL(9) when you want to ignore manually hidden rows but not filter-hidden rows (a less common need).
Another advantage of SUBTOTAL is that it automatically ignores other SUBTOTAL formulas in its range, which prevents double-counting in hierarchical reports.
Using SUBTOTAL with Excel Tables and Structured References
When you work with an Excel Table (created via Insert > Table or Ctrl+T), you can use structured references. For example, if your table is named Sales and you want to sum the Amount column, you can write:
=SUBTOTAL(109, Sales[Amount])
This works exactly like a normal range but is easier to read and automatically adjusts if you add or remove rows. Note that if you add a Total Row to the table (via Table Design > Total Row), Excel automatically inserts a SUBTOTAL(109) formula in the total row, which is why the total updates when you filter the table.
Keyboard Shortcuts and Mac Differences
On Windows, you can quickly insert a SUBTOTAL formula by selecting the cell below a column of numbers and pressing Alt + = (AutoSum). This inserts a SUM, not SUBTOTAL. To get SUBTOTAL, you can type it manually or use the Function Wizard (Shift+F3). On a Mac, the AutoSum shortcut is Command + Shift + T (which inserts SUM), and the Function Wizard is Shift + F3.
For Excel for the web, the SUBTOTAL function works the same, but keyboard shortcuts may differ; the function is fully supported.
Frequently Asked Questions
What does SUBTOTAL(9) mean?
SUBTOTAL(9) means you want to sum the range, and the function will ignore rows that are manually hidden (right-click > Hide). It does not ignore rows hidden by a filter. To ignore filtered rows, use 109 instead.
Why is my SUBTOTAL formula returning 0?
This usually happens when the range contains text or empty cells, and you’re using a function like 1 (AVERAGE) or 2 (COUNT) that only works with numbers. Check that your data is numeric. Also, ensure you haven’t accidentally referenced a range that is entirely hidden or filtered out.
Can SUBTOTAL ignore error values?
No, SUBTOTAL does not ignore error values. If any cell in the range contains an error like #DIV/0!, the SUBTOTAL result will also be an error. For error-tolerant calculations, use AGGREGATE instead.
Does SUBTOTAL work in Google Sheets?
Yes, Google Sheets has a SUBTOTAL function with the same syntax and behavior. However, the function numbers are the same (1–11 and 101–111). In Google Sheets, you can also use the SUBTOTAL formula, but the filtering behavior may differ slightly; it generally works the same.
How do I get a subtotal that updates when I filter?
Use function number 101–111, such as =SUBTOTAL(109, A2:A100) for a sum that updates with filtering. This is the standard way to create a dynamic total in a filtered list.
Can I use SUBTOTAL with multiple ranges?
Yes, you can include up to 254 ranges, like =SUBTOTAL(9, A2:A10, C2:C10). However, note that the function will apply the same operation to all ranges combined, so it sums all values across the ranges.
Related
- How to Make All Columns Fit Text in Excel
- C Battery Size: Dimensions, Weight & Capacity
- K Value for Columns: What It Is and How to Use It
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excel Formula to Uppercase the First Letter in CellsTo uppercase only the first character in an Excel cell while leaving the rest unchanged, use =UPPER(LEFT(A2,1))&MID(A2,2,LEN(A2)). If…
- VLOOKUP Examples in Excel: Formulas That WorkVLOOKUP finds a value in the first column of a range and returns a value from another column…
- R Sequence of Numbers: Generate with seq()The R function for generating a sequence of numbers is seq(), and the simplest call is seq(from =…
- Excel AVERAGEIF With Dates: Formula, Examples, and TipsYes—Excel’s AVERAGEIF can average values for a matching date. With dates in A2:A100, values in B2:B100, and the…
- Match in Excel Without Duplicates: Formulas That WorkTo return values that appear in both Excel lists without repeating them, use =UNIQUE(FILTER(A2:A100,(A2:A100<>"")*ISNUMBER(XMATCH(A2:A100,B2:B100)),"")). With the first list…
- Excel Sum Formula Not Updating? Fixes That WorkIf your Excel SUM formula is not updating, the most common cause is that calculation is set to…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.