KajoData / Excel
Excel SUBTOTAL: make your summary respond to filters
I explain when I use SUBTOTAL instead of SUM, how codes 9 and 109 handle hidden rows, and why intermediate summaries can inflate a grand total.

Your manager asks for sales in the North region. You filter the list, see the right orders, copy the total and send it over. Unfortunately, the total still covers the whole company. In the example from my Polish video, that means reporting 27,040 zł instead of 6,240 zł. The workbook looks reasonable while answering the wrong question.
For summaries like this, I use SUBTOTAL, called SUMY.CZĘŚCIOWE in Polish Excel. Before choosing its first argument, I decide what should change the result: filtering, manually hiding rows, or both. I also check what the column actually represents. Those choices matter more than memorizing a function name.
A filter changes the view while SUM keeps its range
The formula =SUM(E6:E17) still references the same range after you select a region in a filter. Rows disappearing from the screen does not remove them from that reference. If the cell should show company-wide sales regardless of the current view, that behavior may be exactly what you need.
The problem starts with the label. Under “sales for the selected region,” I expect a number that follows the selection. A company-wide total communicates something different. Before changing a formula, I establish what the summary is supposed to mean to the person reading it.
Here is a small synthetic dataset. Headers are in row 5, amounts are in column E, and each data row represents one order. The amounts are numeric cells. This table shows the region and amount; I leave columns B, C and D between them for the other fields.
| Row | A: Region | E: Amount |
|---|---|---|
| 6 | North | 100 |
| 7 | South | 200 |
| 8 | North | 50 |
| 9 | North | 150 |
In B6:B9, I enter identifiers Z1, Z2, Z3 and Z4. In C6:C9, the text product names are Pen, Notebook, Pen and Binder, respectively. Column D contains Completed, except for D8, which contains Cancelled. These fields will support filtering and counting later in the example.
All four amounts sum to 500. Filtering for North leaves 100, 50 and 150 visible, totaling 300. A plain SUM(E6:E9) still returns 500. I am deliberately leaving the cancelled order in the example because it will help distinguish filtering from manually hiding a row.
SUBTOTAL takes an operation code and a reference
For a sales total that follows the filter, I put this formula outside the list, for example in E2:
=SUBTOTAL(9,E6:E9)
The first argument, 9, selects summation. The second identifies the cells containing the amounts. With North selected, the result is 300. Clearing the filter restores 500. I can now reuse the same summary for different regional views without rewriting the reference each time.
There are two required arguments: the operation code and the first reference. Additional references are optional, as shown in Microsoft’s SUBTOTAL documentation. One range is enough here. I keep the summary outside the range it summarizes so that it does not refer to itself.
If you work with Polish Excel, the equivalent is:
=SUMY.CZĘŚCIOWE(9;E6:E9)
I use commas in the English examples and semicolons in the Polish example. Your argument separator depends on regional settings, so match the formulas that already work in your environment. The colon in E6:E9 still denotes a range; it is doing a different job from the separator between arguments.
Codes 9 and 109 treat manually hidden rows differently
I leave the North filter active, then manually hide row 8, the cancelled order. The screen now shows amounts of 100 and 150. With code 9, SUBTOTAL still returns 300. It excludes rows removed by a filter but includes rows hidden manually.
To exclude both, I change the code:
=SUBTOTAL(109,E6:E9)
The result is now 250. Before manually hiding that order, both codes returned 300 for North. The difference appears when rows are hidden manually. The same distinction applies to the two code families, 1-11 and 101-111; both exclude filtered-out rows. Microsoft lists these behaviors alongside the operation codes.
I would avoid making manual hiding the main rule for excluding cancellations. In this example, I would also filter Status to Completed. The reason for excluding the order is then visible in the selection. A definition of sales should survive someone rearranging the view or opening the workbook later.
This also explains why I do not automatically replace every 9 with 109. Someone might hide a few rows simply to make a large workbook easier to inspect. With 109, that changes the result. Whether this is desirable depends on the agreed behavior of the report. I choose the code after making that decision.
Averages and counts depend on the column you choose
Changing the first argument lets the same function produce other summaries. These are the options I use most often. The codes in the right column also exclude manually hidden rows.
| Calculation | Includes manually hidden rows | Excludes manually hidden rows |
|---|---|---|
| Average | 1 | 101 |
| Count numeric cells | 2 | 102 |
| Count nonempty cells | 3 | 103 |
| Sum | 9 | 109 |
I unhide row 8 and keep only the North filter. =SUBTOTAL(1,E6:E9) returns an average of 100: the total of 300 divided by three numeric amounts. Codes 2 and 3 both return 3 for this column because all three visible cells contain numbers.
The Product column shows why those count codes differ. =SUBTOTAL(2,C6:C9) returns 0 because the visible product names are text. Code 3 returns 3. In this small list, that happens to be the number of orders: each row is one order and has a product. If a row represented an order line instead, counting those cells would not necessarily count orders.
The COUNT documentation distinguishes counting numeric entries from counting populated fields. If I want a record count, I choose a column that every record must have. A missing amount should not silently turn into a missing order.
Code 3 needs another distinction. A cell containing a formula that returns "" contains empty text, which COUNTA includes. The screen may look blank even though the cell is not empty. Before labeling the result “completed responses” or “products entered,” I inspect what the chosen column contains.
I also separate the question about order counts from the question about average amounts. If an order has no amount recorded, I need to resolve that missing value before interpreting an average. A plausible result does not establish that the dataset is complete. I would compare the summary of amounts with the count of populated identifiers and investigate any discrepancy at its source.
Intermediate summaries can inflate a grand total
A separate problem appears when regional summaries sit between the detail rows and a grand total sums the entire column. You now have both original amounts and calculations based on those amounts in the same reference.
Imagine a separate little layout: orders worth 100 and 50, followed by their regional subtotal of 150. Then an order worth 200, followed by another regional subtotal of 200. Applying ordinary SUM to all five cells gives 700. The actual orders total 350; the other 350 comes from counting the regional summaries again.
When those regional summaries use SUBTOTAL, another SUBTOTAL covering the whole range ignores the nested subtotals. The grand total includes the original amounts without adding the regional results a second time. This behavior is documented in the function’s remarks.
How those summaries were created matters. A nearby label saying “total” does not give a number special treatment. If I enter 150 manually or calculate it with SUM, I cannot assume that SUBTOTAL will recognize its business meaning and skip it. I prefer consistent formulas or a clear separation between detail data and summary outputs.
Before replacing a formula, I would also confirm that all detail entries represent the same kind of amount. Each order appears once in this example. If someone adds another detail row with the same order value, the correct function can still count that amount again. Ignoring nested subtotals does not remove duplicate data or decide whether cancelled orders belong in the report.

Check the meaning of the report before sending it
I would start with four views: the full list, one region, a status filter and a manually hidden row. For each, I write down the expected behavior. In a tiny example, I can follow every amount. In a company workbook, I inspect a selected part and confirm that the formula covers the intended dataset.
The function is designed for vertical ranges. Hiding a column does not produce the equivalent effect when you subtotal a horizontal row. I therefore avoid extending “only what is visible” into a rule for every workbook layout. This is specific behavior involving rows and filters, rather than a general interpretation of everything hidden on the screen.
For reporting, I also consider an Excel table with a Total Row. Its default dropdown selections use SUBTOTAL, although users can enter other formulas there. I inspect the actual cell rather than trusting its location. For the broader setup, see my guide to creating a proper Excel table.
When sharing the result, I would include the selected period, region and status. That matters especially when a number leaves the workbook for a message or slide. A bare 250 cannot tell the reader whether it covers all orders or only completed North orders. If people need both the company total and the current selection, I show two separately labeled summaries.
Finally, I add a clear label: “visible order sales” or “company-wide sales.” Try that on one summary in your own workbook. Decide what it should mean, then choose the function and operation code. A correct number still needs a description that lets the next person use it correctly.
Key takeaways
Why does SUM stay the same after I apply a filter?
SUM still includes the referenced range, including rows hidden by a filter. Use SUBTOTAL with code 9 or 109 when the summary should respond to filtering.
What is the difference between SUBTOTAL 9 and 109?
Both sum values and exclude filtered-out rows. Code 9 includes manually hidden rows, while 109 excludes those rows as well.
Does SUBTOTAL ignore every intermediate summary?
It ignores nested SUBTOTAL formulas within its references. A SUM formula or a manually entered summary does not automatically receive the same treatment.
AI was used in an automated way while working on this article. If you want to learn how to do it too, check out this project.
