To insert subtotals in Excel with the SUM function, sort or group your data by the field you want to total (for example, Region), then either use Data > Subtotal for an automatic grouped total, or type =SUM() formulas yourself below each group. The automatic route is faster for clean tables; the manual SUM route gives you full control over layout, and it is the only option when your data is not sorted in the default order or when you need subtotals in specific spots only. Everything below works in Excel for Microsoft 365, Excel 2024, 2021 and 2019 on Windows and Mac; the ribbon labels can differ slightly by version and region, so if a name is not exactly as written, look for the closest match on the same tab.
What You'll Need
- A worksheet with clean tabular data: one header row, no blank rows or blank columns inside the range, and numbers stored as numbers, not as text.
- A column that defines your groups (Region, Department, Month, Category), with each group's rows sitting together.
- At least one numeric column to total (Amount, Quantity, Cost).
- Optional but useful: a spare blank row beneath each group if you plan to type SUM formulas manually.
Step-by-Step
Method 1: Automatic subtotals from the Data tab
- Click any single cell inside your data range. Do not select the whole table by hand; Excel needs to detect the block itself.
- If your rows are not already grouped together, sort first: select the range, then go to Data > Sort and sort by your group column (for example Region, A to Z). Subtotal totals each change in that column, so unsorted data produces many tiny, wrong subtotals.
- Go to Data > Subtotal. This sits in the Outline group on the right side of the Data tab.
- In the dialog, set At each change in to your group column. Set Use function to Sum. Tick the numeric columns you want totalled under Add subtotal to. Leave Replace current subtotals ticked if this is your first pass.
- Click OK. Excel inserts a subtotal row after each group, adds a grand total at the bottom, and adds outline buttons (1, 2, 3) at the left edge so you can collapse and expand groups.
- Check one group: click its subtotal cell and confirm the formula in the formula bar looks like
=SUBTOTAL(9,D2:D7). The 9 is the function number for SUM. If you see#VALUE!or a total of 0, your numbers are probably stored as text.
Method 2: Manual SUM subtotals (any layout, any order)
- Insert a blank row after the last row of each group. Right-click the row number and choose Insert, or select several row numbers and insert them all at once.
- In the new row, under the numeric column you want to total, type
=SUM(and then drag over just that group's cells, or type the range directly:=SUM(D2:D9). - Press Enter. Repeat for each group. A quick shortcut: select the whole column of subtotal cells, press Alt+= on Windows (or Cmd+Shift+T on some Mac layouts, or use Formulas > AutoSum), and Excel writes SUM formulas for the contiguous block above each one.
- Add a grand total at the bottom that sums the subtotal cells only, for example
=SUM(D10,D18,D26), or=SUMIF(A2:A100,"<>",D2:D100)/2style approaches are best avoided; simply reference the subtotal cells to avoid counting rows twice. - Format the subtotal rows (bold, a top border) so they read clearly, and freeze the header row via View > Freeze Panes.
Common Mistakes
- Totalling the grand total. If your grand total is
=SUM(D2:D100)and there are subtotal rows inside that range, every figure is counted twice. Sum only the subtotal cells, or use=SUBTOTAL(9,range), which ignores nested SUBTOTAL results. - Unsorted data. Data > Subtotal only fires when the group value changes, so interleaved rows produce repeated, fragmented subtotals.
- Numbers stored as text. Values pasted from another system often carry a leading apostrophe or a stray space and total as zero. Select the column and use Data > Text to Columns > Finish to convert, or check the status bar selection sum as a quick sanity test.
- Blank rows inside the range. Excel stops detecting the table at the first blank row, so the subtotal misses everything below it.
- Using SUM instead of SUBTOTAL in filtered reports. Plain SUM totals hidden rows too; SUBTOTAL(9,...) totals only visible rows.
Tips
- Leave the outline buttons in place; clicking level 2 collapses everything to subtotal rows, which is ideal for printing or screenshotting a summary.
- To remove auto subtotals later, go to Data > Subtotal and click Remove All. That deletes the subtotal and grand total rows but keeps your data.
- Convert the range to a table with Ctrl+T and you can use a PivotTable instead, which produces group totals without touching the original layout.
- Name your ranges (Formulas > Define Name) so
=SUM(January)reads better than a string of cell references. - Round displayed values consistently with Home > Number Format so subtotals and grand totals agree visually.
Troubleshooting
If Data > Subtotal is greyed out, Excel has not recognised a clean range: click inside the data, clear any merged cells, and remove blank rows and columns. If subtotals appear on every single row, the group column is unsorted or contains trailing spaces that make each value unique; sort it and clean the text with Data > Text to Columns > Finish or =TRIM(). If a subtotal returns 0, select the source cells and check the status bar at the bottom of the window; if it shows Count instead of Sum, the values are text. If formulas show as text instead of calculating, the cell is formatted as Text; set it to General and re-enter the formula. If your grand total is double the expected figure, replace the grand total's SUM range with the individual subtotal cells. If the outline numbers vanish, go to File > Options > Advanced and confirm Show outline symbols if an outline is applied is enabled (on Mac, Excel > Preferences > View).
Frequently Asked Questions
What is the difference between SUM and SUBTOTAL?
SUM adds every cell in the range, including rows hidden by a filter. SUBTOTAL(9,range) adds only visible rows and skips other SUBTOTAL results, which is why Excel's automatic subtotal feature uses it.
Can I add subtotals without sorting my data?
Yes, but only manually. Type SUM formulas beneath each group, or build a PivotTable with the group column in Rows and the value column in Values. The automatic Data > Subtotal route requires grouped rows.
How do I add a second level of subtotals?
Run Data > Subtotal again, choose the next group column, and untick Replace current subtotals. Excel nests the new level inside the existing outline.
Why does my subtotal include the row above it?
The range is one row too tall. Edit the formula so it starts on the first data row of the group, not on the header or the previous subtotal row.
How do I delete subtotals but keep the data?
Data > Subtotal > Remove All clears every subtotal and grand total row. For manual formulas, select the subtotal rows, right-click, and choose Delete Row.