Subtotal Sum in Google Sheets: How to Use SUBTOTAL
In this article
To calculate a subtotal in Google Sheets, use the SUBTOTAL function: enter =SUBTOTAL(9,B2:B10) to add the values in B2:B10. The function is especially useful for filtered lists because it can exclude rows hidden by a filter, unlike a regular SUM formula.
What SUBTOTAL Does
SUBTOTAL performs a selected calculation on a range, such as a sum, average, count, minimum, or maximum. Its first argument is a function number that tells Sheets which calculation to perform; the remaining argument is the range or ranges to calculate.
For a subtotal sum, the two function numbers to know are 9 and 109:
=SUBTOTAL(9,B2:B10)sums the range while ignoring rows excluded by a filter. It includes rows hidden manually.=SUBTOTAL(109,B2:B10)sums the range while ignoring rows excluded by a filter and rows hidden manually.
Both formulas include values in visible rows. Choose 9 if manually hidden rows should still count; choose 109 if any hidden row should be left out. If no rows are filtered or hidden, they generally return the same sum.
How to Add a Filtered Subtotal
Suppose a sales table has product names in column A, regions in column B, and sales amounts in column C. To total the visible sales amounts, enter a subtotal formula in an empty cell outside the data range:
With sales values in C2:C100, use =SUBTOTAL(9,C2:C100).
- Select a cell in the table, including its header row.
- Choose Data > Create a filter. Filter controls appear in the header cells.
- Use the filter in the Region column to show only the region you want.
- Enter the formula in a cell outside the filtered range, such as C101, provided that row is not part of the data.
The result updates as you change the filter. For example, if visible sales are 120, 80, and 50, the subtotal returns 250. If filtering hides a row with sales of 40, that value is not included. A normal =SUM(C2:C100) would still include values hidden by the filter.
Keep the formula cell outside the range being summarized. If the subtotal formula includes its own cell, it creates a circular reference. Also avoid placing the total in the middle of a table that you intend to sort or expand.
Choosing the Right Function Number
The function number determines both the calculation and, for certain numbers, how manually hidden rows are treated. Common options include:
- 1 or 101: Average.
- 2 or 102: Count cells containing numbers.
- 3 or 103: Count non-empty cells.
- 9 or 109: Sum.
- 4 or 104: Maximum.
- 5 or 105: Minimum.
For the options from 1 through 11, filtered-out rows are ignored, but manually hidden rows are included. For options from 101 through 111, both filtered-out and manually hidden rows are ignored. Thus, use 9 or 109 for addition, not 1 or 101; those calculate an average.
SUBTOTAL can accept more than one range. For example, with morning sales in B2:B10 and afternoon sales in D2:D10, enter =SUBTOTAL(9,B2:B10,D2:D10) to total both ranges. Make sure the ranges represent the values you intend to count, and keep the formula outside them.
Subtotals by Category
A filter-based subtotal shows a total for whatever rows are currently visible. It does not automatically create a separate total for every category. For instance, filtering a Region column to “West” and using SUBTOTAL gives the West total; changing the filter to “East” recalculates it for East.
If you need a report that displays all category totals at once, consider a pivot table. In Google Sheets, select the data and choose Insert > Pivot table, then use the pivot table editor to add a category under Rows and the amount field under Values. A pivot table groups records and summarizes each group, while SUBTOTAL calculates across a specified range based on what is visible.
You can also build separate category-specific calculations with functions such as SUMIF, but that is a different approach: the category condition is built into each formula, rather than being controlled by the visible filter. Use SUBTOTAL for interactive filtered views; use a pivot table or conditional sum for a grouped summary that stays visible all at once.
Common Problems and Checks
- The total does not change when filtering: Check that the formula uses SUBTOTAL rather than SUM, and that the filter is applied to the rows included in the range.
- The result is zero or too small: Some apparent numbers may be stored as text. Check the cells’ contents and number formatting, and convert text values to numbers if needed.
- The total seems too large after hiding rows: Function number 9 includes manually hidden rows. Use 109 if those rows should also be excluded.
- A row is missing from the result: Confirm that the range includes it. A formula using B2:B10 will not include a value in B11.
- The total appears twice: Make sure the formula’s range does not include another subtotal row that you intended to keep separate.
- The formula reports a circular reference: Move the formula outside the range it totals, or revise the range so it does not include the formula cell.
SUBTOTAL also ignores other SUBTOTAL formulas inside its referenced range. This can help prevent double-counting when a range contains intermediate subtotals. However, it is still important to check the layout: an ordinary SUM can include subtotal rows, and separately constructed ranges may overlap.
SUBTOTAL Compared with SUM
SUM is the straightforward choice when every value in a range should count regardless of filtering. SUBTOTAL is better when a total should respond to a filter. For example, a sales report may use SUM for an all-time grand total and SUBTOTAL for the visible rows in a filtered table.
One common misconception is that SUBTOTAL always excludes every hidden row. That depends on the function number: 9 ignores filtered-out rows but includes manually hidden ones, whereas 109 ignores both. Another is that SUBTOTAL groups records by itself; it does not. It calculates a value for the range supplied, so grouping requires filtering, a pivot table, or another category-based method.
Frequently Asked Questions
What is the formula for a subtotal sum in Google Sheets?
Use =SUBTOTAL(9,range), replacing range with the cells to add. For example, with amounts in B2:B10, use =SUBTOTAL(9,B2:B10).
What is the difference between SUBTOTAL 9 and 109?
Both calculate a sum and exclude rows removed by a filter. Number 9 includes manually hidden rows; number 109 excludes manually hidden rows too.
Does SUBTOTAL update when I filter rows?
Yes. SUBTOTAL recalculates based on the rows left visible by a filter, as long as its range covers the data being filtered.
Can I use SUBTOTAL for more than one column?
Yes. You can provide multiple ranges in one formula, such as =SUBTOTAL(9,B2:B10,D2:D10). Each range should contain values you want included in the same calculation.
Why use SUBTOTAL instead of SUM?
Use SUBTOTAL when the answer should change with a filter. Use SUM when hidden or filtered rows should still count toward the total.