Contact

SUBTOTAL Function in Google Sheets: Syntax, Examples & Compatibility

Math Beginner Google Sheets

Learn how to summarize a filtered list while controlling treatment of hidden rows in Google Sheets. 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: summarize a filtered list while controlling treatment of hidden rows in Google Sheets. The reproducible examples below use explicit values so the formula’s meaning is testable without a large workbook.

Evidence: The function name and syntax are documented in the linked vendor function reference. Expected outputs were independently reasoned or checked outside the application. These are not native Google Sheets test results. A guide being published here does not certify every software release or file-import scenario.

Availability and version history

  • Introduced: Introduction version not established by the official history reviewed.
  • Availability: Documented in the rolling Google Sheets service; examples use the web spreadsheet workflow.
  • Checked: October 14, 2026; official SUBTOTAL reference. Documentation check, not a new native test; existing example-verification notes retain their scope.

Syntax and arguments

=SUBTOTAL(function_code, range1, [range2, ...])

The code and first vertical range are required; additional ranges are optional. Codes 1 through 11 select AVERAGE, COUNT, COUNTA, MAX, MIN, PRODUCT, STDEV, STDEVP, SUM, VAR and VARP, respectively. Adding 100 selects the corresponding hidden-row-skipping form.

Google states that autofilter-excluded cells are ignored for every code. It also excludes referenced cells containing SUBTOTAL calls, preventing nested subtotals from being counted again. The visibility distinction applies to these vertical-range controls, not a blanket hidden-column rule.

Best use case: Summarize a filtered list while controlling treatment of hidden rows.

Set up the example sheet

Enter 10, 20, 30, and 40 in B2:B5. Leave all rows visible for both baseline checks, then try filtering out a row to study the result.

Enter the formula in an unused cell. For a formula returning several values, leave an unobstructed area where those values can expand. These formulas use comma argument separators in a typical English-language locale; commas or semicolons inside quoted text are data, not argument separators. Adapt the separator if your regional settings require it.

Worked example 1: SUBTOTAL with known input

=SUBTOTAL(9,B2:B5)

Expected output: 100.

Sum over four visible rows is 10 + 20 + 30 + 40.

Worked example 2: a second SUBTOTAL case

=SUBTOTAL(1,B2:B5)

Expected output: 25.

Average over the same four values is 100 divided by 4.

Compare both results before replacing literal values or short sample ranges with your own workbook data. For a spilling formula, compare every output cell, not only the top-left result.

Compare manually hidden and filtered rows

Keep the original B2:B5 values 10,20,30,40, with result formulas outside the data range. With no filter active, manually hide the row containing 20:

Formula Expected result
=SUBTOTAL(9,B2:B5) 100
=SUBTOTAL(109,B2:B5) 80
=SUBTOTAL(1,B2:B5) 25
=SUBTOTAL(101,B2:B5) 26.666667

The final value is 80/3, displayed to six decimals. Code 109 skips the manually hidden 20; code 9 retains it.

Restore all rows. Then use an autofilter that excludes only the row containing 30. Codes 9 and 109 now both give 70, and codes 1 and 101 both give 23.333333, because each uses 10,20,40. A filter exclusion is not equivalent to manually hiding a row.

If 20 is also manually hidden while 30 remains filtered out, code 9 gives 70, code 109 gives 50, and code 101 gives 25. Record both visibility operations when reproducing this state.

Advanced example: avoid counting nested subtotals twice

Restore all rows and clear the filter. In B6 enter =SUBTOTAL(9,B2:B3) and in B7 enter =SUBTOTAL(9,B4:B5). Their expected values are 30 and 70.

=SUBTOTAL(9,B2:B7)
=SUM(B2:B7)

Expected results are 100 and 200. The outer SUBTOTAL ignores the two subtotal formula cells. Ordinary SUM adds their displayed numeric values to the four detail values.

This exclusion is documented for cells containing SUBTOTAL calls. It is not a general promise to detect every manually typed total or every formula that happens to aggregate records.

Advanced example: drive a report with an explicit function code

Put code 9 in E2 and enter:

=SUBTOTAL(E2,B2:B5)

With all four detail rows visible, changing E2 to 9,1,4,5,2 gives 100,25,40,10,4: sum, average, maximum, minimum and numeric count. These are different quantities, so keep a matching label and suitable number format beside the result.

The COUNT and COUNTA distinction requires its own type rules. All four cells in this control are numeric, avoiding an unsupported mixed-type shortcut. Statistical-code edge cases, invalid codes, overlapping ranges and arbitrary source errors remain outside these controls.

Visibility is not a saved criterion

The result changes when the included rows change. If a report should always total East records regardless of the current filter, an explicitly criteria-based function such as SUMIF answers that different question.

For a reproducible subtotal, keep the code, source range and filter/manual-hide state together. A screenshot of one total without that state is insufficient to explain its calculation.

Practical advice and troubleshooting

When this formula helps: SUBTOTAL is intended for filtered or collapsible reports. SUM is simpler when hidden-row behavior must not affect a total.

Important edge case: Codes 1–11 differ from 101–111 in manually hidden-row handling, and nested SUBTOTAL cells require special care.

If the result differs, first verify the text-versus-number types of the input cells, the argument separators for your locale, and the range size. For dynamic arrays, inspect occupied cells in the output area. For an imported file, check that the formula is being evaluated in Google Sheets and that its ranges and text survived conversion.

Compatibility and version considerations

This is a cross-program compatibility hot spot because filter visibility and manually hidden rows do not always have the same effect.

Google Sheets is a rolling web service. Confirm the sheet locale and the full result area when checking an imported formula.

Function availability and parameter behavior must be judged for the specific application and release; a function documented in one spreadsheet does not automatically work in another.

Editorial verification: Full dedicated reference and current manuscript reviewed October 14, 2026. Original and added outputs were independently calculated; no native application run, screenshot, or version-specific output is claimed. Review the editorial testing standards if you require stronger proof before importing a workbook.