How to Run a Subtotal in Excel: Step-by-Step Guide
In this article
To run a subtotal in Excel, first sort your data so that the rows you want to group are together, then select any cell in the range and go to Data > Subtotal. Choose the column to group by (for example, a category or region column), pick the function (Sum, Count, Average, etc.), and tick the columns you want subtotalled. Excel inserts a subtotal row after each group and a grand total at the bottom. The steps below cover the built-in Subtotal feature and the SUBTOTAL function, plus what to do when the numbers look wrong.
What You'll Need
- Excel for Windows, Mac, or Excel for the web. The Data > Subtotal command is available on all three, though the exact dialog layout can differ slightly by version and platform.
- A data range with a header row and no completely blank rows or columns inside it. Blank rows break the grouping.
- At least one column you can sort by (a category, region, month, or similar) and at least one numeric column to total.
Step-by-Step
- Make a backup copy of your sheet. Subtotals insert rows into your data, so keep an untouched copy if the layout matters. You can always remove subtotals later with Data > Subtotal > Remove All, but a copy is safer.
- Check the data is clean. Each column should have a single header in row 1. Remove blank rows and merged cells inside the range. If your numbers are stored as text (left-aligned with a green triangle), convert them to numbers first, or the subtotals will show 0.
- Sort by the group column. Select a cell in your data, go to Data > Sort, and sort by the column you want to group on (for example, Region). The Subtotal feature only creates a subtotal when the value in the group column changes, so unsorted data produces one subtotal per row instead of one per group.
- Select any cell inside the data range. Excel usually detects the whole contiguous block automatically. If it does not, select the entire range including headers before opening the dialog.
- Open Data > Subtotal. On Windows it is on the Data tab in the Outline group. On Mac it is under the Data tab as well. In Excel for the web, look for Subtotal on the Data tab; if you do not see it, use the SUBTOTAL function approach described below.
- Set “At each change in” to the column you sorted by (for example, Region). This is the grouping column.
- Set “Use function” to Sum for adding numbers, or Count, Average, Max, Min, etc., depending on what you need.
- Tick the columns to subtotal under “Add subtotal to.” Only numeric columns make sense for Sum. Tick more than one if you want several columns totalled at once.
- Tick “Replace current subtotals” if you are re-running the command on data that already has subtotals, so you do not nest them. Leave “Summary below data” ticked to place the grand total at the bottom.
- Click OK. Excel inserts an outline with subtotal rows after each group and a grand total row at the end. Use the 1, 2, and 3 buttons at the left edge to collapse to grand totals, group subtotals, or show everything.
- Verify a couple of groups. Compare one subtotal against a quick manual sum of that group (select the cells and read the status bar at the bottom of the window). If they match, the rest are almost certainly correct.
If you prefer a formula instead of inserted rows, use =SUBTOTAL(9, range) where 9 means Sum. The SUBTOTAL function ignores rows that are themselves subtotals, which prevents double counting. It also ignores filtered-out rows when you use function numbers 1–11 (for example 9 for Sum), but includes them with 101–111. That makes SUBTOTAL the right choice for totals above a filtered table, where a plain SUM would add hidden rows too.
Common Mistakes
- Not sorting first. This is the most common cause of “it made a subtotal on every row.” The group column must be sorted so identical values sit together.
- Blank rows inside the range. Excel treats a blank row as the end of the data. Delete blank rows before running Subtotal.
- Numbers stored as text. Subtotals show 0 or blank. Convert with Text to Columns or multiply by 1 in a helper column, then paste values back.
- Running Subtotal twice without “Replace current subtotals.” You get nested subtotals and inflated grand totals. Remove all and start again.
- Using SUM instead of SUBTOTAL above a filtered table. SUM adds hidden rows, so the total does not match what you see. Use SUBTOTAL with function number 9.
- Merged cells in the group column. Merged cells break sorting and grouping. Unmerge before you start.
Tips
- Format the subtotal rows with bold or a light fill so they stand out. Do this after inserting them, because re-running Subtotal can wipe manual formatting on those rows.
- Use the outline buttons (1, 2, 3) to collapse groups for printing or screenshots. Level 2 shows subtotals only; level 1 shows just the grand total.
- If you need subtotals by two categories (for example Region then Product), run Subtotal once on the outer group, then run it again on the inner group with “Replace current subtotals” unticked. The result nests, but check the grand total carefully.
- For dashboards that update often, prefer a PivotTable over inserted subtotal rows. A PivotTable gives you grouped totals without changing the source layout.
- Keep a helper column with a unique ID if you plan to sort back to the original order later. Sorting is required for Subtotal, and Excel cannot undo a sort after you save.
Troubleshooting
- Every row gets its own subtotal. The group column is not sorted. Sort by that column and run Data > Subtotal again with “Replace current subtotals” ticked.
- Subtotals are 0 or blank. The numeric column contains text. Select it, use Data > Text to Columns > Finish, or check for leading apostrophes and spaces.
- The Subtotal command is greyed out. You are likely editing a cell, inside a PivotTable, or the sheet is protected. Press Esc, click outside any table, and unprotect the sheet via Review > Unprotect Sheet if you have the password.
- Grand total is double the expected figure. Subtotals were applied twice. Data > Subtotal > Remove All, then reapply once.
- Subtotal option missing in Excel for the web. Use the SUBTOTAL function in a cell below the data, or open the file in the desktop app, where the full Data > Subtotal dialog is available.
- Subtotals disappeared after filtering. They are still there; the outline may be collapsed. Click the level 3 button on the left, or clear the filter via Data > Clear.
Frequently Asked Questions
What is the difference between SUM and SUBTOTAL?
SUM adds every cell in the range, including hidden or filtered rows and any subtotal rows inside it. SUBTOTAL ignores other subtotal rows and, with function numbers 1–11, ignores filtered-out rows. That makes SUBTOTAL safer for totals above a filtered table.
Can I subtotal by more than one column?
Yes. Run Data > Subtotal once for the outer group, then again for the inner group with “Replace current subtotals” unticked. Check the grand total afterwards, because nesting is easy to get wrong.
How do I remove subtotals?
Select a cell in the data, go to Data > Subtotal, and click Remove All. This removes the subtotal rows and the outline. It does not undo any sorting you did.
Why does my subtotal show 0?
The numbers are stored as text. Convert the column to numbers (Text to Columns, or retype without an apostrophe) and the subtotal will calculate.
Does Subtotal work on a filtered list?
The Data > Subtotal command works on the visible range, but results can be confusing with filters applied. Clear filters first, apply subtotals, then filter. For totals that must respect filters, use the SUBTOTAL function instead.
Can I use Subtotal in Excel for the web?
The Data tab in Excel for the web may not show the full Subtotal dialog depending on your version. The SUBTOTAL function works everywhere, and the desktop app has the complete feature.