Yes, you can create a subtotal formula that only adds specific items based on a label. The standard solution is the SUMIFS function, which allows you to sum a range of numbers while ignoring rows that do not match a specific condition. This guide shows how to build this formula from scratch.

What You'll Need

  • A computer with Microsoft Excel installed (2019, 2021, or Microsoft 365). The steps below apply to both Windows and Mac versions, though slight differences in keyboard shortcuts may exist.
  • A dataset with at least two columns: one column containing the values you want to sum (e.g., Prices, Scores, or Hours) and another column containing the category or label (e.g., Product Name, Region, or Status).
  • A cell where you want the final calculated subtotal to appear.

Step-by-Step

  1. Organize your data in a table. For the most reliable results, highlight your entire dataset (including headers) and press Ctrl+T (Windows) or Cmd+T (Mac) to convert it into an official Excel Table. This allows you to name the ranges easily and prevents errors if you add new rows later.
  2. Identify your ranges. You need to know the range of numbers to sum and the range of labels to check. For example, if your sales numbers are in column B and your categories are in column A, your sum range is B:B and your criteria range is A:A.
  3. Open the Formula Bar. Click into the empty cell where you want the subtotal to appear. Press the equals key (=) to start typing.
  4. Enter the SUMIFS function. Type SUMIFS (all caps is acceptable, but lowercase works too). The function requires a specific order of arguments: SUMIFS(sum_range, criteria_range1, criteria1).
  5. Select the Sum Range. After typing SUMIFS(, click and drag to select the column of numbers you want to add up (e.g., B2:B100). This is the first argument.
  6. Select the Criteria Range. Immediately after the closing parenthesis of the sum range, type a comma , and then click and drag to select the column containing the labels (e.g., A2:A100). This tells Excel where to look for the condition.
  7. Enter the Criteria. Type another comma , and then specify exactly what you want to match. You can type the text directly (e.g., , "Electronics",) or reference a cell that contains that text (e.g., , E2,).
  8. Close the parentheses and press Enter. Type ) to finish the formula and hit Enter. Excel will calculate the sum of all numbers in column B that correspond to the label in column A.
  9. Handle multiple conditions (optional). If you need to subtotal by two categories (e.g., Electronics AND Q1), you can add more arguments by typing additional commas and selecting new criteria ranges and values (e.g., , A2:A100, "Q1",).

Common Mistakes

The most frequent error when writing a conditional subtotal formula is mixing up the order of the range arguments. Unlike the older SUMIF function, SUMIFS requires the Sum Range to be the very first argument. If you put the Criteria Range first, the formula will return a #VALUE! error or a result of zero.

Another common issue is failing to account for case sensitivity. By default, Excel treats "Apple" and "apple" as the same word. If you need to distinguish between them, you must wrap the criteria in the EXACT function, which is case-sensitive (e.g., EXACT(A2:A100, "Apple")).

Tips

Using structured references with Excel Tables makes your formulas much easier to read and maintain. Instead of typing B2:B100, you can type [Total] and [Category]. This automatically expands the formula if you insert new rows at the bottom of your table.

For quick subtotals, you can use the AutoFilter feature. Once your data is a table, click the dropdown arrow on the Category header, uncheck "Select All,” and only check the specific item you want to subtotal. Excel will display a small summary line at the bottom of the column with the count and sum of the filtered items. Note that this is a view-only feature and does not create a permanent formula in a cell.

Troubleshooting

If your formula returns zero or an incorrect number, the first thing to check is the data formatting. Ensure that the Sum Range and Criteria Range are both set to the correct format (Number or Text). If one range is formatted as Text and the other as Number, Excel cannot match them, and the condition will fail.

If you see a #VALUE! error, it usually means there are non-numeric values in your Sum Range. SUMIFS will ignore text in the Sum Range, but it cannot handle errors like #N/A or #DIV/0! that might be hiding inside the data. Use the IFERROR function to wrap your sum range, which will replace errors with zero before summing (e.g., SUMIFS(IFERROR(B2:B100,0), A2:A100, "Electronics")).

Frequently Asked Questions

Can I use a wildcard in a conditional subtotal?

Yes, you can use asterisks (*) and question marks (?) as wildcards. An asterisk matches any sequence of characters, and a question mark matches a single character. For example, to subtotal everything containing "East" in the category column, you would use the criteria "*East*" in your formula.

How do I subtotal based on a date range?

To subtotal based on dates, you can use comparison operators. For example, to sum all sales from January 1st to January 31st, you would use >="1/1/2023" as the first criteria and <="1/31/2023" as the second. Note that your computer's regional date settings must be compatible with the dates entered in the formula.

Why does my formula count blank cells?

SUMIFS treats blank cells as zeros, so they are included in the total. If you want to exclude blank cells, you must add a specific condition to your formula. For example, SUMIFS(B:B, A:A, "Electronics", B:B, <>"") will sum only Electronics that have a value in column B.

What is the difference between SUMIF and SUMIFS?

The main difference is that SUMIF can handle only a single condition, while SUMIFS can handle up to 127 conditions. SUMIF requires the sum range to be the last argument, whereas SUMIFS requires the sum range to be the first argument.

How do I subtotal using a dropdown list?

You can create a dropdown list in a cell using the Data Validation feature. Once the list is created, reference that cell in your SUMIFS formula. This allows you to create a dynamic dashboard where you can change the category in the dropdown list, and the subtotal will update automatically.

Can I subtotal based on cell color?

Standard Excel formulas, including SUMIFS, cannot directly look at cell color or font style. To subtotal by color, you must use a helper column with an IF function that checks the background color of the cell (e.g., =IF(A2=1,1,0)) and then sum that column, or use a VBA macro or the FILTER function with a custom enumeration.