What subtotals do and when to use them
Subtotals in Excel automatically insert summary rows that calculate sums, averages, counts, or other totals for groups of data in your spreadsheet. When you use Excel's Subtotal feature, it breaks your data into sections, adds a subtotal row after each section, and usually adds a grand total at the bottom. This is different from manually typing formulas — Excel does the grouping and math for you.
Subtotals work best when your data is already sorted by the column you want to group by. For example, if you have a list of sales by region, you would sort by region first, then apply subtotals. Excel will then show a subtotal for each region and a grand total for all regions combined.
The feature also adds outline buttons on the left side of your spreadsheet, which let you collapse and expand each group to see just the subtotals or all the detail rows. This is useful when you have hundreds of rows and want to focus on the summary numbers.
Key Takeaways
- Your data must be sorted by the column you want to group by before you apply subtotals — Excel groups consecutive rows with the same value in that column.
- The Subtotal feature lives in the Data menu and will automatically insert rows with formulas that calculate sums, averages, counts, or other totals for each group.
- Excel adds outline buttons (numbered 1, 2, 3) on the left margin that let you show only subtotals, only grand totals, or all rows at once.
- You can remove subtotals by going back to the Data menu and choosing Remove All, which deletes the inserted rows and restores your original data.
Sort your data before adding subtotals
Excel's Subtotal feature groups your data based on identical values in one column. If your data is not sorted by that column, the grouping will not work correctly — Excel will create a new subtotal row every time the value changes, even if the same value appears again later.
To sort your data, first select all of it, including headers. Click the Data menu, then click Sort. In the Sort dialog, choose the column you want to sort by (the column you will group by for subtotals), and click OK. Your data is now arranged so that all rows with the same value in that column sit together.
If your data has headers, make sure the "My data has headers" checkbox is checked in the Sort dialog. This tells Excel not to sort the header row along with the data.
Open the Subtotal dialog and choose your settings
Once your data is sorted, select all of it again, including headers. Click the Data menu at the top of the screen. Look for the Subtotals option — in most versions of Excel it appears in the Data menu. Click it to open the Subtotals dialog box.
The dialog has three main fields. The first is "Change to each time the value in" — this is already set to the column you sorted by, but you can change it if needed. The second field is "Use function" — this is where you choose what calculation to perform. The default is Sum, but you can also choose Average, Count, Max, Min, and several others. The third field is "Add subtotal to" — this is where you select which columns should have the subtotal calculation applied.
For example, if you sorted by Region and want to sum the Sales column for each region, you would leave the first field set to Region, keep the second field set to Sum, and check only the Sales column in the third field. Then click OK.
Review the outline buttons and navigate your subtotals
After you click OK, Excel inserts subtotal rows and adds outline buttons on the left side of your spreadsheet. You will see numbers 1, 2, and 3 in a small box on the left margin. These buttons control what you see on the screen.
Click the 1 button to show only the grand total row. Click the 2 button to show each group's subtotal row plus the grand total. Click the 3 button to show all rows — the detail rows, the subtotal rows, and the grand total. You can also click the plus and minus signs next to individual groups to expand or collapse just that group.
The subtotal rows themselves contain formulas. If you click on a subtotal cell, you will see a formula in the formula bar that looks like =SUBTOTAL(9,C5:C10). The 9 means Sum; different numbers represent different functions. You can edit these formulas if needed, but usually you do not have to.
Remove subtotals when you no longer need them
If you want to go back to your original data without the subtotal rows and outline buttons, select all your data again and open the Data menu. Click Subtotals. In the dialog box, click the Remove All button. Excel will delete all the inserted subtotal rows and remove the outline buttons, leaving your sorted data intact.
Removing subtotals does not undo your sort — your data will still be sorted by the column you sorted by earlier. If you want to return to the original order, you will need to sort by a different column or undo the sort manually.
Common mistakes and how to avoid them
The most common mistake is forgetting to sort your data first. If you apply subtotals to unsorted data, you will get a subtotal row for every change in value, which defeats the purpose. Always sort by the grouping column before you open the Subtotals dialog.
Another mistake is selecting the wrong column in the "Add subtotal to" field. If you want to sum sales by region, make sure you check the Sales column, not the Region column. Checking the Region column will try to sum text, which does not work.
A third mistake is forgetting to include your headers when you select your data. If you do not include headers, Excel may treat the first row of data as a header, or it may not recognize your data structure correctly. Always select from the first cell of your headers down to the last cell of your data.
Using subtotals with filtered data
If you have already filtered your data to show only certain rows, you can still apply subtotals. Excel will apply the subtotal formulas only to the visible rows, which is often exactly what you want. However, be aware that if you remove the filter later, the subtotal formulas will still be there and will include all rows again.
If you apply subtotals to filtered data and then remove the filter, the subtotal rows will still calculate based on all rows, not just the filtered ones. This is usually fine, but it is something to keep in mind. If you want to change which rows are included in the subtotals, remove the subtotals first, adjust your filter, and then reapply subtotals.
Frequently Asked Questions
Can I use subtotals on multiple columns at once?
Yes. After you apply subtotals the first time, you can apply them again to a different column without removing the first set. Excel will add another layer of grouping. However, this can make your spreadsheet complex and hard to read, so use this feature carefully and only when you have a clear reason to group by multiple columns.
What if I want to calculate something other than a sum?
In the Subtotals dialog, click the "Use function" dropdown and choose a different option. You can select Average, Count, Max, Min, Product, and several others. The subtotal rows will then show that calculation instead of a sum.
Do the subtotal formulas update if I change the data?
Yes. The subtotal formulas are live formulas, so if you change a number in one of the detail rows, the subtotal row for that group will recalculate automatically. However, if you add new rows of data after applying subtotals, those new rows will not be included in the subtotals — you will need to remove and reapply subtotals.
Can I copy just the subtotal rows to another sheet?
Yes. Click the 2 button on the outline to show only the subtotal rows and grand total. Then select and copy those rows. When you paste them into another sheet, only the visible rows will be copied. This is a quick way to create a summary sheet with just the totals.
What happens if I sort my data after adding subtotals?
If you sort after adding subtotals, the subtotal rows will move around and your grouping will break. Always remove subtotals before you sort, then reapply them after sorting if you need them again.