How to Put Subtotal in Excel: Step-by-Step Guide
In this article
To put a subtotal in Excel, use the SUBTOTAL function (for example, =SUBTOTAL(9, B2:B10)) or the Data > Subtotal feature for automatic grouped totals. Both methods let you sum filtered or grouped data while ignoring other subtotals, so your totals stay accurate when you hide rows or apply filters. This guide walks you through both approaches, plus common pitfalls and fixes.
What You'll Need
- Microsoft Excel (any modern version, including Microsoft 365, Excel 2019, 2021, or Excel for Mac). The steps below use the desktop app; the web version has similar but slightly different menus.
- A dataset with a header row and numeric columns you want to subtotal.
- Basic familiarity with selecting cells and entering formulas.
Step-by-Step
- Organize your data. Make sure your data is in a clean table: one header row, no blank rows or columns inside the data, and each column contains one type of value. For the Data > Subtotal feature, you will need a column to group by (for example, Region or Category).
- Decide on your method. Use the SUBTOTAL function for a single total that respects filters, or use Data > Subtotal to insert multiple subtotal rows automatically for each group.
- Method A: Using the SUBTOTAL function. Click the cell where you want the subtotal. Type
=SUBTOTAL(9, range)and press Enter. Replacerangewith the cells you want to sum, e.g.,=SUBTOTAL(9, B2:B10). The number 9 tells Excel to sum; use 1 for AVERAGE, 2 for COUNT, 3 for COUNTA, 4 for MAX, 5 for MIN, etc. The SUBTOTAL function automatically ignores other SUBTOTAL results and rows hidden by filters, so it is ideal for filtered lists. - Method B: Using Data > Subtotal. Select any cell inside your data range. Go to the Data tab on the ribbon and click Subtotal (in the Outline group). In the dialog box, choose the column to group by (e.g., Region), the function (Sum, Count, Average, etc.), and the column to subtotal (e.g., Sales). Click OK. Excel inserts subtotal rows after each group and a grand total at the bottom. Note: menu labels can differ slightly by version, device, or region.
- Adjust or remove subtotals. To change options, reopen Data > Subtotal and adjust settings. To remove all subtotals, open the dialog again and click Remove All. To remove individual subtotal rows, select the row and delete it.
- Use the outline symbols. After using Data > Subtotal, Excel adds outline buttons (1, 2, 3) on the left side. Click 1 to show only grand totals, 2 to show subtotals, and 3 to show all rows. This helps you collapse and expand groups quickly.
- Verify your totals. Check that the subtotal values match manual sums for a few groups. If you used the SUBTOTAL function, test by applying a filter and confirming the total updates to show only visible rows.
Common Mistakes
- Using SUM instead of SUBTOTAL. SUM includes hidden rows and other subtotals, which can double-count. SUBTOTAL is designed to ignore them.
- Including subtotal rows in the range. If you use SUM over a range that already contains subtotals, you will add them twice. SUBTOTAL avoids this by ignoring other SUBTOTAL results.
- Forgetting to sort or group data first. The Data > Subtotal feature requires your data to be sorted by the group column; otherwise, it creates separate subtotals for each change in value.
- Leaving blank rows. Blank rows can break the data range and cause subtotals to be placed incorrectly.
- Overlooking the function number. Using the wrong number (e.g., 1 for AVERAGE instead of 9 for SUM) gives unexpected results.
Tips
- Convert your data to an Excel Table (Ctrl+T) before adding subtotals; tables automatically expand and make formulas easier to manage.
- Use SUBTOTAL with filters for dynamic reports: the total updates as you filter rows.
- For multiple levels of grouping, use Data > Subtotal repeatedly with different group columns, and check the "Replace current subtotals" box to avoid duplicates.
- Press Alt+= (AutoSum) to quickly insert a SUBTOTAL formula when your data is filtered; Excel often suggests SUBTOTAL automatically.
- Keep a backup copy before applying Data > Subtotal, as it modifies your sheet structure.
Troubleshooting
- Subtotal gives wrong result after filtering: Ensure you used SUBTOTAL, not SUM. Also check that the range does not include hidden rows you want to include.
- Data > Subtotal is grayed out: Make sure you have selected a cell within a contiguous data range and that the sheet is not protected. Unprotect via Review > Unprotect Sheet if needed.
- Subtotals appear in wrong places: Sort your data by the group column first. Then reapply Data > Subtotal.
- Cannot remove subtotals: Open Data > Subtotal and click Remove All. If that fails, manually delete the subtotal rows or use Undo (Ctrl+Z).
- Formula returns #VALUE!: Check that the range contains only numbers; text or errors in the range will cause errors. Use SUBTOTAL with the appropriate function number.
Frequently Asked Questions
What is the difference between SUM and SUBTOTAL?
SUM adds all numbers in a range, including hidden rows and other subtotals. SUBTOTAL can sum, average, count, etc., while ignoring rows hidden by filters and other SUBTOTAL results, making it safer for filtered lists.
Can I use SUBTOTAL with filtered data?
Yes. SUBTOTAL is designed to work with filters; it automatically excludes rows hidden by filters. Use function number 9 for sum, 1 for average, etc.
How do I subtotal only visible cells?
Use the SUBTOTAL function with the appropriate function number (e.g., 9 for sum). It ignores rows hidden by filters but includes manually hidden rows. For manual hiding, use function number 109 to ignore manually hidden rows as well.
Why does Data > Subtotal not work?
Common reasons: data not sorted by the group column, blank rows in the data, or the sheet is protected. Sort your data and ensure no blank rows, then try again.
Can I have multiple subtotals in one sheet?
Yes. You can use Data > Subtotal multiple times with different group columns, or use SUBTOTAL formulas in multiple cells. Just avoid overlapping ranges that include other subtotals.
Does SUBTOTAL work in Excel for Mac?
Yes, the SUBTOTAL function and Data > Subtotal feature are available in Excel for Mac. Menu locations may differ slightly.