
Section: Excel & Google Sheets
The SUBTOTAL function in Excel adds up a list and ignores anything hidden by a filter. =SUBTOTAL(9,B2:B200) gives the sum of the visible rows only, and it updates the moment you change the filter. That one behaviour is why it belongs at the bottom of any table you filter often. This guide covers the function numbers, the difference between the 1 to 11 and 101 to 111 ranges, the Data, Subtotal command, and the cases where AGGREGATE is the better tool. The sample data is made up.
What SUBTOTAL does
SUBTOTAL runs one of eleven calculations on a range: average, count, count of non empty cells, max, min, product, standard deviation, variance and sum. You choose which one with a number in the first argument. It then applies that calculation while skipping rows that a filter has hidden, which a plain SUM does not do. If you filter a sales table to one region and the total at the bottom still shows the whole country, you are looking at SUM. Replace it with SUBTOTAL and the number follows the filter.
The function numbers
The first argument is a code, not a value. Microsoft lists them in pairs:
- 1 or 101: AVERAGE
- 2 or 102: COUNT
- 3 or 103: COUNTA
- 4 or 104: MAX
- 5 or 105: MIN
- 6 or 106: PRODUCT
- 7 or 107: STDEV
- 8 or 108: STDEVP
- 9 or 109: SUM
- 10 or 110: VAR
- 11 or 111: VARP
The low numbers include rows you hid by hand with Hide Rows. The 100 series ignores them. Both always ignore rows removed by a filter, which is the part people miss. In practice, use 9 for a sum and 109 when you want manual hiding to matter too.

Add a subtotal to a filtered list
- Put the formula below the data, outside the filtered range, for example in B201.
- Type =SUBTOTAL(9,B2:B200).
- Apply a filter with Data, then Filter, and pick a region.
- Watch the total change as the visible rows change.
Keep the formula out of the filtered range, or it will be hidden and filtered along with the data. A row directly under the last data row is fine as long as it is not inside the range you selected for the filter.
The Data, Subtotal command
Excel can build the whole thing for you. Sort the data by the column you want to group, select the table, then use Data, then Subtotal. Choose the group column, the calculation and the column to subtotal. Excel inserts SUBTOTAL rows for each group and a grand total at the end, and it adds outline buttons on the left so you can collapse the groups. It is the fastest way to produce a printed report with group totals, and each row it writes is an ordinary SUBTOTAL formula you can edit afterwards.

Why nested subtotals do not double count
SUBTOTAL ignores other SUBTOTAL results inside its range. That is deliberate, and it is what makes a grand total safe. If each region has its own SUBTOTAL row and the grand total is also a SUBTOTAL over the whole column, the grand total skips the region rows and adds only the detail lines. A SUM in the same place would add the detail and the region totals, and the answer would be wrong. This is the main reason to use the function in a report rather than plain addition.
SUBTOTAL compared with SUM
Use SUM when you want all referenced values included, regardless of visibility. Use SUBTOTAL when the sheet will be filtered, when rows will be hidden by hand, or when group totals and a grand total share a column. For a condition based total, such as sales in one region only, SUMIF or SUMIFS is still the right tool, and our SUMIF guide covers the criteria syntax. SUBTOTAL has no criteria argument at all.

When to use AGGREGATE instead
AGGREGATE does everything SUBTOTAL does and adds two things: it can ignore error values, and it can ignore hidden rows and nested subtotals with a wider set of options. If a column contains #DIV/0! or #N/A from a lookup that found nothing, SUBTOTAL returns an error too, while AGGREGATE with the right option still gives a number. For a clean table, SUBTOTAL is enough and simpler to read. For a messy one, AGGREGATE saves a cleanup step.
Counting visible rows
SUBTOTAL(2,range) counts numbers and SUBTOTAL(3,range) counts non empty cells, both on visible rows only. That is how you show "23 of 140 orders" under a filtered table: one SUBTOTAL(3,...) for the visible count and COUNTA for the full count. Pair it with a conditional count if you need a threshold, as in COUNTIFS with multiple criteria.
Common problems
- The total does not change with the filter. The formula is SUM, not SUBTOTAL, or the referenced cells are not the rows affected by that filter.
- The total includes hidden rows. You used a number from 1 to 11. Use 101 to 111.
- The grand total is double the real figure. A SUM is adding the group subtotals. Use SUBTOTAL for the grand total too.
- #VALUE! appears. One of the references is a 3-D reference across several sheets, which SUBTOTAL does not accept.
- Totals look wrong in a horizontal layout. SUBTOTAL is built for columns. For a row of values, the hidden column behaviour does not work as expected.
- A PivotTable would be simpler. If you need totals by two or three groups, a PivotTable is usually less work than stacked SUBTOTAL rows.

Questions and answers
Does SUBTOTAL ignore filtered rows automatically?
Yes, with any function number. That behaviour is built in, unlike manual hiding, which only the 100 series ignores.
Can I use SUBTOTAL with a condition?
Not directly. It has no criteria argument. Use SUMIFS for conditions, or filter the list and let SUBTOTAL follow the filter.
What is the difference between SUBTOTAL(9) and SUBTOTAL(109)?
9 includes rows you hid by hand, 109 skips them. Both skip rows hidden by a filter.
Does SUBTOTAL work in Google Sheets?
Yes, with the same function numbers, and it also follows filters there.
Why does my SUBTOTAL show a smaller number than expected?
Some rows are hidden, or the range stops short. Check the range ends on the last data row.
