
📎 This article includes 1 downloadable practice file ↓
In this article
SUBTOTAL calculates a sum, count, average and more while ignoring rows hidden by a filter. It also ignores other SUBTOTALs in the range, so totals never double-count.
Syntax
=SUBTOTAL(function_num, ref1, [ref2], ...)
| Argument | What it means |
|---|---|
function_num |
9 = SUM, 1 = AVERAGE, 2 = COUNT, 3 = COUNTA, 4 = MAX, 5 = MIN. Add 100 (109, 101…) to also ignore manually hidden rows. |
ref1 |
The range to calculate. |
Examples
Example 1
=SUBTOTAL(9, E2:E500)
Sum of only the visible (filtered) rows.
Example 2
=SUBTOTAL(3, A2:A500)
How many rows are visible after filtering.
Example 3
=SUBTOTAL(109, E2:E500)
Also skips rows you hid by right-click → Hide.
SUBTOTAL in practice
Where you will use it
- Totals that ignore hidden or filtered rows
- Sum visible rows only after filtering
- Counts in grouped reports
Worked example
9 = SUM, 1 = AVERAGE, 3 = COUNTA.
| Function no. | Apr | May | Jun | Formula | Result |
|---|---|---|---|---|---|
| 9 | 100 | 200 | 300 | =SUBTOTAL(A2,B2:D2) | 600 |
| 1 | 100 | 200 | 300 | =SUBTOTAL(A3,B3:D3) | 200 |
| 3 | 100 | 200 | 300 | =SUBTOTAL(A4,B4:D4) | 3 |
Results calculated in Excel.
Mistakes people make
| Mistake | What to do instead |
|---|---|
| Using 9 when rows are hidden manually | Use 109 to ignore manually hidden rows too |
| Nested subtotals | SUBTOTAL ignores other SUBTOTALs, avoiding double counting |
Related functions
📚 Part of the free Excel course: Beginner → Expert · Try it in the Formula Lab or ask the AI Helper.
Test formulas dynamically in our web formula laboratory or download the companion Excel workbook.
📎 Practice files for this article
- 📗Practice workbook: Math & rounding24 tasks on realistic sales data — type your formula, the Check column turns green when it is right. Answers sheet included.⬇ XLSX · 35 KB
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time — plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul →Build this skill next
This page is a quick function reference. Use it for syntax, then practise the function in a broader workflow.
Stuck on a step? Ask a question and the AI answers using this article.