SUBTOTAL function
Returns a sum, count, average and more for a list, ignoring rows hidden by a filter and other SUBTOTAL results.
Available in All versions of Excel, Excel for the web, Excel for Mac
In every Excel versionWorks in Google Sheets
Syntax
SUBTOTAL(function_num, ref1, [ref2], ...)| Argument | What it means | |
|---|---|---|
function_num | Required | Which calculation: 1 AVERAGE, 2 COUNT, 3 COUNTA, 4 MAX, 5 MIN, 6 PRODUCT, 7 STDEV, 8 STDEVP, 9 SUM, 10 VAR, 11 VARP. Add 100 (101–111) to also ignore rows you hid manually. |
ref1 | Required | The range to calculate on. |
ref2, ... | Optional | Up to 253 more ranges. |
Returns: The chosen statistic for the visible cells of the range.
How SUBTOTAL works
SUBTOTAL is one function that can behave like eleven: SUM, COUNT, AVERAGE, MAX and others, selected by the first argument. What makes it special is visibility. When you filter a table, SUBTOTAL only uses the rows that are still showing, so a total under a filtered list always matches what you see. It is the formula Excel writes in a table's Total Row and in Data > Subtotal.
There are two sets of codes. Codes 1–11 ignore rows hidden by a filter but include rows you hid by hand (right-click > Hide). Codes 101–111 ignore both. In both cases, any cell in the range that itself contains a SUBTOTAL (or AGGREGATE) formula is skipped, so you can put group subtotals inside a list and still get a correct grand total over the whole column without double counting.
SUBTOTAL works on vertical ranges; hiding columns does not affect it. It cannot skip error values — for that, and for more functions such as MEDIAN or LARGE, use AGGREGATE.
Examples
1Total of a list (and of what is left after filtering)
| A | B | C | |
|---|---|---|---|
| 1 | Rep | Region | Sales |
| 2 | Ana | East | 4200 |
| 3 | Ben | West | 3150 |
| 4 | Chloe | East | 5100 |
| 5 | Dev | North | 2800 |
| 6 | Ema | West | 3900 |
| 7 | 19,150 |
Result: 19,150
With no filter the result equals SUM. Filter Region to East and the same formula shows 9,300 because only Ana and Chloe are visible.
2Grand total that skips group subtotals
| A | B | C | |
|---|---|---|---|
| 1 | Region | Rep | Sales |
| 2 | East | Ana | 4200 |
| 3 | East | Chloe | 5100 |
| 4 | East total | 9300 | |
| 5 | West | Ben | 3150 |
| 6 | West | Ema | 3900 |
| 7 | West total | 7050 | |
| 8 | 16,350 |
Result: 16,350
C4 and C7 hold =SUBTOTAL(9,C2:C3) and =SUBTOTAL(9,C5:C6). The grand total ignores them, so it is 16,350, not 32,700. A plain SUM over C2:C7 would double count.
3Ignore a row hidden by hand
| A | B | |
|---|---|---|
| 1 | Product | Stock |
| 2 | Bolts | 340 |
| 3 | Nuts | 515 |
| 4 | Washers (old) | 120 |
| 5 | Screws | 410 |
| 6 | Rivets | 95 |
| 7 | 1360 |
Result: 1360
Assume row 4 (discontinued washers) was hidden with right-click > Hide. Code 109 skips it and returns 1,360; code 9 would still include it and return 1,480.
4Count visible rows in a filtered list
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Rep | Region | Sales | 5 | |
| 2 | Ana | East | 4200 | ||
| 3 | Ben | West | 3150 | ||
| 4 | Chloe | East | 5100 | ||
| 5 | Dev | North | 2800 | ||
| 6 | Ema | West | 3900 |
Result: 5
103 is COUNTA for visible rows. Unfiltered it returns 5; filter to West and it returns 2, which is handy for a "showing X of 5 reps" label.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#VALUE! | function_num is not 1–11 or 101–111. | Use one of the listed codes; for other functions use AGGREGATE. |
#DIV/0! | Average (1/101) of a range where every row is filtered out or empty. | Wrap in IFERROR or check the filter. |
Error in the data | A cell in the range holds an error, which SUBTOTAL passes through. | Use =AGGREGATE(9, 7, range) to ignore errors and hidden rows. |
Tips
- Put SUBTOTAL formulas above the header row so they stay visible while the filter changes the list.
- In an Excel Table, tick Total Row and choose Sum/Average from the drop-down; Excel writes SUBTOTAL with 109/101 for you.
- Codes 1–11 and 101–111 behave the same on filtered rows; the difference is only rows hidden manually or by grouping.
- Combine with a helper column
=SUBTOTAL(103, A2)to flag visible rows, then use SUMIFS on that flag for conditional visible-only totals.
Questions
What is the difference between 9 and 109?
Both ignore rows hidden by a filter. 109 also ignores rows hidden manually or collapsed by grouping; 9 includes them.
SUBTOTAL or AGGREGATE?
AGGREGATE can also ignore error values and offers 19 functions including MEDIAN, LARGE and PERCENTILE. SUBTOTAL is simpler and works in every Excel version.
Google Sheets
SUBTOTAL also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
SUBTOTAL in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Dutch | SUBTOTAAL |
| Finnish | VÄLISUMMA |
| French | SOUS.TOTAL |
| German | TEILERGEBNIS |
| Hungarian | RÉSZÖSSZEG |
| Italian | SUBTOTALE |
| Norwegian (Bokmål) | DELSUM |
| Polish | SUMY.CZĘŚCIOWE |
| Russian | ПРОМЕЖУТОЧНЫЕ.ИТОГИ |
| Spanish | SUBTOTALES |
| Swedish | DELSUMMA |
| Turkish | ALTTOPLAM |
Recipes that use SUBTOTAL
- How to count cells by color in Excel
- How to freeze panes in Excel
- How to shade alternate rows in Excel
- How to sum only visible cells in Excel