SUBTOTAL Function in Microsoft Excel: Syntax, Examples & Compatibility
Learn how to summarize a filtered list while controlling treatment of hidden rows in Microsoft Excel. Includes syntax, two verified-by-reasoning results, troubleshooting and portability notes.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
Quick answer: SUBTOTAL summarizes a vertical list while excluding filtered-out rows. Choose codes 1–11 to include manually hidden rows or 101–111 to exclude them. Nested SUBTOTAL results are skipped, which prevents counting the same detail twice.
Availability and version history
- Introduced: Original introduction is not established. Microsoft documents manual-hidden-row exclusion starting in Excel 2003; that is feature history, not the function’s first release.
- Availability: Official help lists Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel 2024, Excel 2024 for Mac, Excel 2021, Excel 2021 for Mac, Excel 2019, Excel 2016.
- Checked: October 14, 2026; official SUBTOTAL reference. Documentation check, not a new native test; existing example-verification notes retain their scope.
Syntax and operation codes
=SUBTOTAL(function_num, ref1, [ref2], ...)
The operation code and first reference are required. Microsoft allows up to 254 range/reference arguments. The two code families perform the same calculations; their manual-row visibility policy differs.
| Calculation | Include manually hidden rows | Exclude manually hidden rows |
|---|---|---|
| Average | 1 | 101 |
| Numeric count | 2 | 102 |
| Nonempty count | 3 | 103 |
| Maximum | 4 | 104 |
| Minimum | 5 | 105 |
| Product | 6 | 106 |
| Sample standard deviation | 7 | 107 |
| Population standard deviation | 8 | 108 |
| Sum | 9 | 109 |
| Sample variance | 10 | 110 |
| Population variance | 11 | 111 |
All codes exclude rows removed by a filter. The statistical names in Microsoft’s table use the legacy STDEV/STDEVP and VAR/VARP spellings; the numeric code determines the calculation.
Set up the original controls
Enter 10, 20, 30 and 40 in B2:B5, with every row visible and no filter excluding a record. Put results outside that range. These are ordinary numeric cells, with no embedded subtotal formulas.
=SUBTOTAL(9,B2:B5)
Expected output: 100, from 10+20+30+40.
=SUBTOTAL(1,B2:B5)
Expected output: 25, from 100/4. These preserve both original worked formulas. Use English function names and adapt comma separators for your locale. The expectations are independent models of the documented rules, not a native filter demonstration.
Example 3: manually hide one row
On the baseline data, manually hide row 3, containing 20. Do not filter out any records. Compare:
=SUBTOTAL(9,B2:B5)
=SUBTOTAL(109,B2:B5)
=SUBTOTAL(101,B2:B5)
Expected results are 100, 80 and approximately 26.666667. Code 9 still includes the hidden 20. Code 109 totals 10+30+40, and code 101 divides that 80 by its three included numeric observations.
Changing a row’s visual state changes the selected population for the 100-series codes. Keep the operation code visible in an audit rather than assuming every subtotal means “what I can see.”
Example 4: filter exclusion applies to both families
Restore all rows. Add headers Include in A1 and Amount in B1. Set A2:A5 to Keep, Keep, Skip, Keep, then apply the client’s filter to show only Keep. Row 4, containing 30, is now excluded by filtering.
Codes 9 and 109 both return 70, while codes 1 and 101 both return 70/3, approximately 23.333333. A manually hidden row and a filtered-out row are different cases.
With that filter still active, additionally hide row 3 manually. The modeled code-9 total remains 70, but code 109 becomes 50, from 10+40. Code 1 remains 70/3; code 101 becomes 25. Reset the filter and hidden rows before comparing the clean baseline again.
Advanced example: nested subtotals do not count twice
In a separate visible block, put 10 and 20 in D2:D3 and enter =SUBTOTAL(9,D2:D3) in D4. Put 30 and 40 in D5:D6, then =SUBTOTAL(9,D5:D6) in D7.
=SUBTOTAL(9,D2:D7)
=SUM(D2:D7)
The nested subtotals are 30 and 70. The outer SUBTOTAL ignores those two subtotal cells and returns 100. Ordinary SUM includes all six displayed numeric results and returns 200. The distinguishing feature is the nested SUBTOTAL formula, not a bold font or the word “Total” in an adjacent label.
Do not place the outer formula inside D2:D7, which would make it refer to itself. Also do not infer that every arbitrary calculation labeled as a total receives SUBTOTAL’s nesting exclusion.
Advanced example: the visible average needs a visible denominator
Suppose manually hidden row 3 is excluded using code 101. The correct average is 80/3. Dividing SUBTOTAL(109,B2:B5) by the original four-row count instead gives 20, answering a different question.
Keep the numerator and denominator on the same selected rows. For these entirely numeric controls, codes 109 and 102 select the corresponding sum and numeric count. Mixed text, formula-empty values and source errors require their own operation-specific type rules; this guide does not certify that full matrix.
Horizontal ranges, errors and choosing an alternative
This visibility behavior is designed for vertical records. Microsoft explicitly says hiding a column does not alter a horizontal subtotal such as SUBTOTAL(109,B2:G2). Transposing a report therefore does not preserve a hidden-row policy automatically.
A reference spanning multiple worksheets, such as a 3-D sheet range, has a documented #VALUE! result. SUBTOTAL is not a universal error-cleaning function: AGGREGATE supplies explicit error-exclusion options. For a fixed condition such as a department name, SUMIFS expresses criteria; it does not automatically make a visible-only total.
Before distributing a report, document which rows were filtered, which were manually hidden and which code was used. Exported copies need their own visibility and recalculation check. No particular menu path, save-time filter persistence or native client timing is certified by these arithmetic models.
Related guides and official documentation
Editorial verification: Full manuscript and dedicated Microsoft reference reviewed on October 14, 2026. Original title, publication date, worked formulas and input fixtures are preserved. Expectations were independently calculated from explicit text, array or row-selection models; no native Excel execution, visibility interaction, maximum-size benchmark or file-interchange test was performed.