The SUBTOTAL function in Google Sheets returns a subtotal for a range of cells, and its real power is that it can ignore hidden rows and can be nested inside other SUBTOTAL calls. The syntax is =SUBTOTAL(function_code, range1, [range2, ...]), where the function code is a number from 1–11 (including hidden values) or 101–111 (ignoring hidden values). For example, =SUBTOTAL(9, A2:A10) sums the visible cells in A2:A10, and =SUBTOTAL(109, A2:A10) sums only the rows that are not hidden by a filter or manually hidden.
What the Function Codes Mean
The first argument is a number that tells SUBTOTAL which operation to perform. The codes 1–11 include manually hidden rows; codes 101–111 ignore rows hidden by filters or by right-clicking > Hide row. The codes map to existing functions:
- 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)
Note that the 100-series codes (101–111) ignore rows hidden manually or by a filter, but they do not ignore rows hidden by grouping (outlines) unless those rows are also manually hidden. In practice, most people use 9 and 109 for sums.
How to Use SUBTOTAL in Google Sheets
You can type the function directly or insert it from the menu. The direct approach works like any other function:
- Click the cell where you want the subtotal.
- Type
=SUBTOTAL(– a helper box will show the list of codes. - Enter the code (for example,
9for sum) and then the range, likeA2:A10. - Close the parenthesis and press Enter.
Example: With sales amounts in B2:B20 and a filter applied to show only the “East” region, =SUBTOTAL(109, B2:B20) returns the sum of the visible East rows only. If you use =SUBTOTAL(9, B2:B20), it still sums only the visible rows because the 9 code ignores rows hidden by a filter? Actually no – the 9 code includes hidden rows in the calculation, but when a filter is active, hidden rows are still hidden from the calculation? Let’s be precise: In Google Sheets, the 1–11 codes include rows hidden by a filter? The official documentation says that 1–11 ignores only manually hidden rows? The truth is: codes 1–11 include rows hidden by a filter, and codes 101–111 ignore rows hidden by a filter or manually. So if you have a filter active, =SUBTOTAL(9, B2:B20) will still sum all rows, including those filtered out. That is a common misconception. Always use the 100-series codes (like 109) if you want to respect filters.
Why Use SUBTOTAL Instead of SUM or AVERAGE?
The main reasons are:
- It ignores hidden rows – when you filter or hide rows, the 100-series codes recalculate automatically.
- It ignores other SUBTOTAL formulas – if your range contains other SUBTOTAL calls, they are not double-counted, which is useful for grand totals.
- It works with the Subtotal menu – Data > Subtotal (or the Subtotal button in a table) inserts SUBTOTAL formulas automatically.
- It is compatible with Excel – the same syntax works in Excel, so skills transfer.
For example, if you have a list of orders with subtotals per region, using =SUBTOTAL(109, C2:C100) at the bottom gives a grand total that excludes the region subtotal rows if those rows are themselves SUBTOTAL formulas? Actually, SUBTOTAL ignores other SUBTOTAL formulas only if they are in the same range? Yes, when you reference a range that contains SUBTOTAL formulas, those nested subtotals are ignored, preventing double counting.
Common Problems and Fixes
Here are typical issues users run into:
- Filter not being ignored: You used code 9 but the filter still changes the result? That’s because 9 includes hidden rows. Switch to 109.
- Hidden rows not ignored: You used 109 but manually hidden rows are still counted? That happens if you hid rows via grouping (outlines) – the 100-series codes ignore only rows hidden by filter or row hide, not group collapse. To ignore grouped rows, you need to manually hide them or use a different approach.
- Getting a #VALUE! error: This usually means the function code is outside 1–11 or 101–111, or the range contains text in a numeric operation (e.g., using AVERAGE on text). Check the range.
- Subtotals not updating: If you change data, SUBTOTAL recalculates automatically, but if you have manual calculation turned off (File > Settings > Calculation > On change), it won’t update until you hit F9 or Ctrl+R.
SUBTOTAL vs. Other Aggregation Functions
Compare SUBTOTAL to SUM, AVERAGE, COUNT, and the newer functions like QUERY or ARRAYFORMULA:
- SUM/AVERAGE/COUNT – always include all rows, even hidden ones. No way to ignore filters.
- QUERY – can aggregate with grouping, but requires a query language and doesn’t automatically respond to filters on the sheet.
- FILTER + SUM – you can do
=SUM(FILTER(B2:B20, A2:A20="East")), but it ignores the sheet’s filter state and is static. - SUBTOTAL – the only native function that respects filter/hidden state and ignores nested subtotals.
For a quick total that updates when you filter, SUBTOTAL is the best choice. For complex criteria, use QUERY or FILTER.
How to Insert SUBTOTAL Automatically
Google Sheets can insert SUBTOTAL formulas for you when you create a table or use the Subtotal feature:
- Select your data range and go to Data > Create a filter (or use the filter icon).
- After applying a filter, click the filter icon on a column and you’ll see a “Sum” option at the bottom? Actually, that shows a quick sum in the status bar, not a formula.
- To insert a subtotal row, you can use Data > Subtotal? That menu exists in Excel, not Google Sheets. In Google Sheets, you have to type the formula manually or use the “Functions” menu > “SUM” and then change it to SUBTOTAL.
There is no one-click “Subtotal” button in Google Sheets like in Excel. Instead, you can use the “Explore” button (bottom-right) to get a quick sum, but it doesn’t insert a formula. The most reliable way is to type it yourself.
Frequently Asked Questions
Does SUBTOTAL work with filtered rows? Yes, but only if you use the 100-series codes (101–111). For example, =SUBTOTAL(109, A2:A100) sums only the rows visible after a filter. The 1–11 codes ignore filters and include all rows.
Can I use SUBTOTAL with multiple ranges? Yes, you can add more ranges as additional arguments, like =SUBTOTAL(109, A2:A10, C2:C10). It will sum the visible cells across both ranges.
Why does my SUBTOTAL return 0? Check if the range contains only text or blanks. Also, if you used code 2 (COUNT) on text, it returns 0 because COUNT only counts numbers. Use 3 (COUNTA) for non-empty cells.
Does SUBTOTAL work in Excel? Yes, the same syntax works in Excel, but note that Excel’s SUBTOTAL ignores rows hidden by filters only when you use the 100-series codes, same as Sheets. The function code list is identical.
Can I nest SUBTOTAL inside another SUBTOTAL? Yes, but it’s not recommended unless you understand the behavior. SUBTOTAL ignores other SUBTOTAL formulas that are within its range, so a grand total can exclude subtotal rows. For example, if you have subtotal rows in B5 and B10, and you do =SUBTOTAL(109, B2:B10), the result will sum only the non-subtotal cells.
How do I get a subtotal for each group in a list? You can use the QUERY function with GROUP BY, or you can use the Data > Pivot table feature. SUBTOTAL is not designed for grouping; it’s for a single range. For grouped subtotals, use a pivot table or QUERY.
Related
- Table Saw Crosscut Sled: Build or Buy Guide
- What Is a Data Entry Job? Duties, Pay & Skills
- Google Sheets Query and Filter: How They Differ
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Google Sheets Query Label Multiple ColumnsYes, you can label multiple columns in a single Google Sheets QUERY function by using multiple label clauses…
- How to Open the Text Import Wizard in Excel on WindowsTo open Excel’s legacy Text Import Wizard in Microsoft 365 for Windows, first enable it at File >…
- Shortcut for File Explorer: Best Ways to Open It FastThe fastest shortcut for File Explorer in Windows is pressing Windows + E — it opens File Explorer…
- How to Insert a Check Box in Word Using Alt+X ShortcutTo insert an empty check box in Word on Windows, type 2610 and press Alt+X; Word converts the…
- How to Add a Date Stamp to a Checkbox in ExcelTo add an automatic date stamp to an Excel checkbox, place the checkbox in column B, use the…
- How to Insert a Table of Contents in a Word DocumentTo insert a table of contents in Word, apply built-in heading styles to your section titles, click where…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.