When you use Subtotal in Excel, applying a formula directly to the subtotal row requires using functions that ignore hidden rows, such as SUBTOTAL or AGGREGATE, to ensure accurate results when filtering or grouping data. This method ensures your calculations update dynamically as you show or hide rows, unlike standard functions like SUM or AVERAGE that include hidden data.

What You'll Need

  • A dataset with numeric values organized in columns
  • Excel 2007 or later (SUBTOTAL function is available in all modern versions)
  • Data grouped or filtered using Excel’s Subtotal feature or manual filtering

Step-by-Step

  1. Ensure your data is formatted as a table or has consistent headers. If not, select your data range and press Ctrl + T to convert it to a structured table — this helps Excel recognize data boundaries.
  2. Go to the Data tab on the Ribbon, then click Subtotal in the Outline group. This opens the Subtotal dialog box.
  3. In the dialog box, under "At each change in", select the column that defines your groups (e.g., Region, Department, or Product Category).
  4. Under "Use function", choose the calculation you want (e.g., Sum, Average, Count) — this determines what subtotal Excel creates for each group.
  5. Under "Add subtotal to", check the boxes for each numeric column you want to subtotal (e.g., Sales, Quantity).
  6. Leave "Replace current subtotals" checked if you’re updating existing subtotals; uncheck it if you want to preserve prior subtotals.
  7. Check "Summary below data" if you want subtotals to appear after each group; leave unchecked to place them above.
  8. Click OK. Excel inserts subtotal rows and groups your data with collapsible outlines.
  9. Now, to apply a formula that respects these subtotals, click the cell where you want the total of all subtotals to appear — typically at the very bottom of your dataset.
  10. Type =SUBTOTAL(9, range) where "range" is the column you want to total (e.g., =SUBTOTAL(9, D2:D100) for column D). The number 9 tells Excel to use SUM while ignoring hidden rows.
  11. Press Enter. The formula now sums only visible rows in the filtered or grouped range, including the subtotals you created.
  12. Test the result: Filter one of your group columns to hide some rows. The grand total should update automatically to reflect only visible subtotals.

Common Mistakes

  • Using SUM() instead of SUBTOTAL() — this includes hidden rows and breaks the dynamic behavior you’re trying to achieve.
  • Referencing the entire column (e.g., D:D) in SUBTOTAL — this can cause performance issues and unintended results if there’s extra data below your table.
  • Applying the formula before inserting subtotals — the formula won’t recognize the group structure unless subtotals are already inserted.
  • Manually typing "Total" labels instead of using Excel’s auto-generated subtotal rows — this prevents Excel from properly identifying which rows to ignore.
  • Using AGGREGATE() with incorrect function numbers — AGGREGATE(9,3,range) is the equivalent of SUBTOTAL(9,range), but mixing function codes (e.g., 1 instead of 9) will calculate averages or counts instead of sums.

Tips

  • Use SUBTOTAL(109, range) instead of 9 if you want to ignore manually hidden rows (not just filtered ones) — 109 is the version that excludes rows hidden by manual row hiding.
  • Combine SUBTOTAL with structured table references (e.g., SUBTOTAL(9, Table1[Sales])) for automatic range expansion when new rows are added.
  • Use the AutoSum button after selecting the cell below your data — Excel often suggests SUBTOTAL automatically if subtotals are already present.
  • Press Alt + = (on Windows) or Cmd + Shift + T (on Mac) to trigger AutoSum; it detects the last subtotal row and creates a SUBTOTAL formula for you.
  • When working with large datasets, consider using PivotTables for more complex subtotals — they handle grouping and summaries more efficiently than the Subtotal tool.
  • Never delete subtotal rows manually — use the Subtotal dialog again and click "Remove All" to cleanly clear them.

Troubleshooting

  • If your grand total doesn’t update when filtering, check that your formula uses SUBTOTAL() and not SUM(). Replace any SUM() references immediately.
  • If Excel says "There is a problem with this formula," verify your range doesn’t include text headers or blank cells — SUBTOTAL only works with numeric data.
  • If subtotals appear in the wrong place, re-run the Subtotal tool and confirm "Summary below data" is set correctly.
  • If you see multiple subtotals per group, you likely ran Subtotal twice. Click Data > Subtotal > Remove All, then start over.
  • If the formula returns #VALUE!, check that the referenced column contains only numbers or blank cells — no text or error values.
  • On Mac, ensure you’re using the Excel for Mac version that supports SUBTOTAL — older versions (pre-2016) may not handle all function codes.
  • If filtering doesn’t collapse the outline, go to Data > Group > Ungroup all, then reapply subtotals.

Frequently Asked Questions

Can I use SUBTOTAL with multiple columns at once?

No, each SUBTOTAL formula applies to one column. You must create separate formulas for each numeric column you want to total.

Why does my grand total show zero even though data is visible?

This usually means the range in your SUBTOTAL formula includes headers or non-numeric data. Adjust the range to start from the first data row, not the header.

What’s the difference between SUBTOTAL(9) and SUBTOTAL(109)?

SUBTOTAL(9) ignores rows hidden by filters; SUBTOTAL(109) ignores rows hidden manually (by right-clicking and hiding). Use 109 if users hide rows individually.

Can I use SUBTOTAL in a PivotTable?

PivotTables have their own summary options and don’t need SUBTOTAL. Use the built-in Sum, Average, or Count settings in the Values area instead.

Does SUBTOTAL work with filtered data in Excel Online?

Yes, SUBTOTAL works the same in Excel Online as in the desktop version. Ensure you’re not using legacy features that are unsupported.

Can I nest SUBTOTAL inside another function like IF?

Yes, you can use SUBTOTAL inside IF, SUMIFS, or other functions. For example: =IF(SUBTOTAL(109, D2:D100)>1000, "High", "Low") is valid and useful for conditional logic on visible data.