You can calculate a subtotal in Excel by using the SUMIFS function to sum values that meet specific conditions, or the SUBTOTAL function combined with a filter to dynamically update totals as you hide or show rows. This guide covers the most practical methods for subtotaling data based on criteria, including handling multiple conditions and dynamically updating totals as you filter your list.

What You'll Need

  • A computer with Microsoft Excel installed (Excel 2016, 2019, Excel for Microsoft 365, or Excel for the Web are supported).
  • A spreadsheet containing at least one column of numbers you wish to sum and at least one column of criteria (text or numbers) to filter by.
  • A basic understanding of cell references (e.g., A1, B2) and how to type formulas into the formula bar.
  • A keyboard and mouse (or a touchscreen and stylus if using Excel on a tablet).

Step-by-Step

  1. Prepare your data. Ensure your data is organized in a clean table format. The first row should contain headers for each column. For example, if you are summing sales, your headers might be "Region", "Product", and "Amount". The criteria column should be in a single column, and the values to sum should be in a separate column.
  2. Identify your criteria. Decide exactly what condition you want to apply. For instance, you might want to sum all "Electronics" sales or all sales "Greater than 1000". Write this criteria down, as you will need to reference it in your formula.
  3. Open a new cell. Click on the cell where you want the subtotal to appear. This cell should be outside of your main data range, typically in a summary area or a separate column next to your data.
  4. Start the SUMIFS formula. Type "=" followed by "SUMIFS" into the formula bar. The SUMIFS function is the most robust way to subtotal based on criteria because it allows you to specify multiple conditions. The syntax is "=SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)".
  5. Define the sum_range. The first argument is the range of cells containing the numbers you want to add up. Click and drag to select these cells. For example, if your sales amounts are in column C (from C2 to C100), select C2:C100.
  6. Define the criteria_range1. The second argument is the range of cells you want to check against your criteria. This should be the same size as your sum_range. If you are filtering by product, select the column containing the product names. For example, if your products are in column B (from B2 to B100), select B2:B100.
  7. Enter the criteria1. The third argument is the actual criteria you want to apply. This can be a number, a text, or a cell reference. For example, if you want to sum "Electronics", type "Electronics" in quotes, or click on the cell containing the word "Electronics". If you want to sum values greater than 1000, type ">1000".
  8. Add additional criteria (optional). If you need to subtotal based on more than one condition, you can add more criteria_range and criteria pairs. For example, if you want to sum "Electronics" sales in the "North" region, you would add a criteria_range for the region (e.g., A2:A100) and its corresponding criteria (e.g., "North"). The formula would look like: =SUMIFS(C2:C100, B2:B100, "Electronics", A2:A100, "North").
  9. Close the parenthesis and press Enter. Finish the formula by typing the closing parenthesis ")" and press Enter. Excel will calculate the subtotal and display the result in the selected cell.
  10. Verify the result. Double-check the result by manually adding a few numbers that meet your criteria to ensure the formula is working correctly. You can also use Excel's "Inspect Workbook" feature (found in the File tab) to check for formula errors.

Using SUBTOTAL with Automatic Filters

Another powerful way to subtotal data is by using the SUBTOTAL function in combination with Excel's built-in filtering. This method updates the subtotal automatically whenever you change the filter settings, making it ideal for interactive reports.

  1. Convert your data to a Table. Select your data range (including headers) and go to the Insert tab on the ribbon. Click "Table" and select OK. This will convert your data into an official Excel table, which allows for automatic filtering.
  2. Enable AutoFilter. Once your data is a table, you will see filter arrows appear in the header row. Click on the header of the column you want to filter by (e.g., "Region"). Select the criteria you want to apply (e.g., "North"). Excel will hide the rows that do not match your criteria.
  3. Insert the SUBTOTAL formula. Click on the cell where you want the subtotal to appear. Type "=" followed by "SUBTOTAL". The syntax for the SUBTOTAL function is "=SUBTOTAL(function_num, range1, [range2], ...)".
  4. Define the function_num. The first argument is a number that specifies which function to use. For adding, use 9. For averaging, use 1. For counting, use 2. A full list of function numbers is available in Excel's help documentation.
  5. Select the range. The second argument is the range of cells you want to subtotal. Click and drag to select the column containing the numbers you want to sum. For example, if your sales amounts are in column C (from C2 to C100), select C2:C100.
  6. Close the parenthesis and press Enter. Finish the formula by typing the closing parenthesis ")" and press Enter. Excel will calculate the subtotal based on the currently visible rows.
  7. Test the dynamic subtotal. Change the filter criteria (e.g., switch from "North" to "South"). You will see the subtotal in your formula cell update automatically to reflect the new data set.

Common Mistakes

  • Incorrect range sizes. A common error is selecting sum_range and criteria_range with different numbers of rows. Excel requires these ranges to be identical in size. If they are not, Excel will return a #VALUE! error.
  • Forgetting quotes around text criteria. When using text in your criteria (e.g., "Electronics"), you must enclose it in double quotes. If you forget the quotes, Excel will interpret the text as a cell reference and return an error.
  • Mixing up SUMIFS and SUMIF. SUMIF is used for a single condition, while SUMIFS is used for multiple conditions. If you try to use SUMIF with multiple criteria, Excel will return an error. Always use SUMIFS when you have more than one condition.
  • Using relative references incorrectly. When copying and pasting formulas, it is important to use absolute references (e.g., $A$1) for the criteria range if you want to keep the criteria fixed while the sum range changes.
  • Not accounting for hidden rows in SUBTOTAL. The SUBTOTAL function is designed to ignore rows hidden by filters. If you want to include hidden rows in your subtotal, you should use the SUM function instead.

Tips

  • Use named ranges. Instead of typing cell references like "A2:A100" in your formulas, you can define a named range for your data. This makes your formulas easier to read and less prone to errors.
  • Use the AutoSum button. Excel has a built-in AutoSum button that can automatically insert a SUMIFS or SUBTOTAL formula for you. Select the cell where you want the formula to appear and click the AutoSum button on the Home tab.
  • Use structured references. If you have converted your data to a table, you can use table names and column headers in your formulas.
  • Check for data types. Ensure that the data in your sum_range and criteria_range is of the correct type. For example, if you are summing numbers, make sure there are no text values in the range. If there are, you may need to use the VALUE function to convert them to numbers.
  • Use the Evaluate Formula tool. Excel has a built-in Evaluate Formula tool that allows you to step through a formula one calculation at a time. This can be very helpful for debugging complex formulas.

Troubleshooting

If your subtotal formula is not working as expected, follow these steps to identify and fix the problem.

  1. Check for #VALUE! errors. If you see a #VALUE! error, it is usually because the sum_range and criteria_range have different sizes. Verify that the ranges you selected are identical.
  2. Check for #NAME? errors. If you see a #NAME? error, it is usually because you misspelled the function name. Ensure that you have typed "SUMIFS" or "SUBTOTAL" correctly.
  3. Check for #REF! errors. If you see a #REF! error, it is usually because you have deleted rows or columns that were referenced in your formula. Check your formula for references that no longer exist.
  4. Check for incorrect results. If your formula is returning a result but it is not the expected subtotal, check your criteria. Make sure you are using the correct text, number, or operator.
  5. Check for hidden rows. If you are using SUBTOTAL and your result is different from what you expect, check if there are any hidden rows in your data range. SUBTOTAL ignores hidden rows, so your result will be based on the visible rows only.
  6. Reset the formula. If you have tried all of the above and the formula is still not working, try deleting the formula and starting over. Sometimes, a simple restart of Excel can fix minor glitches.

Frequently Asked Questions

Can I subtotal based on a date range?

Yes, you can subtotal based on a date range by using the SUMIFS function. You can specify the date range as your criteria. For example, to sum values between January 1st and January 31st, you can use the formula: =SUMIFS(C2:C100, A2:A100, ">="&DATE(2023,1,1), A2:A100, "<="&DATE(2023,1,31)).

How do I subtotal based on multiple criteria in different columns?

To subtotal based on multiple criteria in different columns, use the SUMIFS function. You can add as many criteria as you need by adding more criteria_range and criteria pairs. For example, to sum "Electronics" in the "North" region, you would use the formula: =SUMIFS(C2:C100, B2:B100, "Electronics", A2:A100, "North").

What is the difference between SUMIFS and SUMIF?

The main difference is that SUMIFS can handle multiple conditions, while SUMIF can only handle a single condition. SUMIFS is the newer function and is recommended for most cases.

Why is my SUBTOTAL formula not updating when I filter?

If your SUBTOTAL formula is not updating when you filter, it is likely because you are using the SUM function instead of the SUBTOTAL function. The SUM function does not update based on filters. Ensure that you are using the SUBTOTAL function with the correct function number.

Can I use wildcards in my criteria?

Yes, you can use wildcards in your criteria to match partial text. The asterisk (*) matches any sequence of characters, and the question mark (?) matches any single character. For example, to sum all products that start with "A", you can use the criteria "A*".

How do I subtotal based on the color of a cell?

Excel does not have a built-in function to subtotal based on cell color. However, you can use VBA (Visual Basic for Applications) to create a custom function that checks the color of a cell and adds it to the subtotal.