Microsoft’s spread­sheet programme lets you produce com­pre­hens­ive tables and complex cal­cu­la­tions. Functions in Excel can assist in many situ­ations and are rarely affected by the design and ap­pear­ance of your tables. Want to hide certain cells for clarity? No problem: The functions still count the filtered values. However, you may not always want that. If you want your cal­cu­la­tions to react to filters and hidden cells, the SUBTOTAL function is quite useful. It combines multiple cal­cu­la­tion op­er­a­tions and gives you more control over the cells Excel includes.

What do you need Excel’s SUBTOTAL function for?

You may not always want to see all cells, es­pe­cially if you are working with large volumes of data. You can hide rows or certain values in order to make it easier to work with com­pre­hens­ive tables. This reduces tables to a size that only shows the essential data, which makes it far simpler to work with them. However, the hidden values are not lost – they are still part of the worksheet and are therefore still used for cal­cu­la­tion functions. That is a major advantage of Excel.

But what is generally an advantage can also be a problem in some situ­ations. For example, if you want the Excel functions to react to what is currently visible and adapt your results ac­cord­ingly, you can’t do so with the normal cal­cu­la­tion methods. You would have to create a new table that does not include the values that are filtered out. The SUBTOTAL function gives you an al­tern­at­ive: You can configure the function to prevent hidden cells being included in the cal­cu­la­tion.

SUBTOTAL combines no less than eleven different functions: Users choose which cal­cu­la­tion method is to be used in the function, and whether to include hidden cells or not. The function does not include values currently hidden by a filter in the cal­cu­la­tions. Ac­cord­ingly, SUBTOTAL is ideal as an ad­di­tion­al result to com­ple­ment the final result. Comparing the two values often gives ad­di­tion­al in­form­a­tion.

Note

SUBTOTAL can only utilise its full range of functions if the values are arranged ver­tic­ally. If a row is hidden in a case like this, that can influence the cal­cu­la­tion if required. However, if the values are arranged ho­ri­zont­ally, i.e. in one row, and a complete column is hidden, this change never affects the result.

SUBTOTAL syntax

The­or­et­ic­ally, the SUBTOTAL only needs two items of in­form­a­tion. First, specify which cal­cu­la­tion is to be performed. The second and all following arguments contain in­form­a­tion on the range of cells used. One entry is required, but you can add up to 254 ranges to the formula.

=SUBTOTAL(Function;Reference1;[Reference2];…)

The first parameter transfers the prop­er­ties of another function to the SUBTOTAL function – Excel provides a list of functions. You enter the cor­res­pond­ing number and SUBTOTAL performs the cor­res­pond­ing cal­cu­la­tion. However, there are two numbers for every function. Values between 1 and 11 configure SUBTOTAL to include hidden values. If you enter 101 to 111, the function ignores hidden cells in the specified range. Here is an overview.

Hidden cells remain part of the cal­cu­la­tion:

  • 1: AVERAGE
  • 2: COUNT
  • 3: COUNTA
  • 4: MAX
  • 5: MIN
  • 6: PRODUCT
  • 7: STDEV
  • 8: STDEVP
  • 9: SUM
  • 10: VAR
  • 11: VARP

Hidden cells are not included in cal­cu­la­tions:

  • 101: AVERAGE
  • 102: COUNT
  • 103: COUNTA
  • 104: MAX
  • 105: MIN
  • 106: PRODUCT
  • 107: STDEV
  • 108: STDEVP
  • 109: SUM
  • 110: VAR
  • 111: VARP
Note

No matter which group you choose a parameter from, the values currently hidden in a table by the filter are never included in cal­cu­la­tions.

SUBTOTAL in practice: Examples of the function

Cal­cu­lat­ing a sum is the best example of the SUBTOTAL function. Besides the final result including all values, the function also lets you calculate only the values not affected by filters or hidden values.

=SUBTOTAL(109;A2:A10;B2:B10)

In this example, we take values from two columns and add them. As we entered 109 for the first para­met­ers, only values that are currently visible are included.

The same settings work with other cal­cu­la­tion methods. For example, you can calculate the average.

=SUBTOTAL(1;A2:A10;B2:B10)

You can also combine SUBTOTAL with other functions. Ac­cord­ingly, the result of the function can be passed on directly to other cal­cu­la­tions – without requiring auxiliary cells. For example, you can add up multiple subtotals.

It can also be helpful to combine SUBTOTAL with the IF function. You can set up a cell in which you specify the required cal­cu­la­tion type – for example using a drop-down menu. While that makes the formula itself somewhat longer, once you write it you never have to edit it af­ter­wards. For example, if we assume that you want to switch between the three cal­cu­la­tions SUM, COUNT and AVERAGE regularly.

=IF(A12="SUM";SUBTOTAL(109;B2:B10);IF(A12="COUNT";SUBTOTAL(102;B2:B10);IF(A12="AVERAGE";SUBTOTAL(101;B2:B10))))

Use Auto­Fil­ter to set the data that to be in­cor­por­ated, and choose the required cal­cu­la­tion from the dropdown list. The IF queries then always run the correct SUBTOTAL function.

Cal­cu­lat­ing subtotals using the Excel tool

Besides the function, which is easy to integrate in formulas, Excel offers another tool of the same name. You can find it in the “Data” tab under the “Subtotal” button. This tool is useful if you have a multi-column list in Excel, for example. You can include a fixed set of values (generally non-numerical) – for example names – in one column. In turn, these entries are assigned to numerical values: revenues, point scores, meas­ure­ments and similar data. The tool helps you calculate subtotals from groups – all identical entries in one column are grouped and the cor­res­pond­ing values in the other column are cal­cu­lated.

Fact

This tool, which you can launch at the push of a button, uses the SUBTOTAL function in the back­ground. The tool completes the formulas for you and enters them in the right cells.

Before you can use the Subtotal feature, you have to do some pre­lim­in­ary work. The tool accesses a sorted list. You can find the sort function by right-clicking the list area, for example. The columns in your list also require labels in the first row.

If you select the list and open the Subtotal tool, Excel opens a new menu. First, select the column to be used for grouping there. (You need to label the columns for this, as you select the cor­res­pond­ing range using the name rather than a cell reference.) In the next step, you choose the cal­cu­la­tion to be performed. You can choose from the same functions available in the SUBTOTAL function. Finally, choose the values to which the cal­cu­la­tion is to apply. You can specify multiple values. You can also make three changes which are more cosmetic in nature.

  • Replacing existing subtotals: Do you want the list to show subtotals from various cal­cu­la­tions, or only to show the last cal­cu­la­tion? You can specify that here.
  • Insert page breaks between groups: There is a page break after each group list.
  • Show results under the data: The subtotal for every group is shown directly under the re­spect­ive group.

If you confirm your entries, Excel changes the view a little. You now also have an ad­di­tion­al menu on the left margin, re­flect­ing the nesting of your list. You can show or hide the groups using the cor­res­pond­ing buttons and adapt the view to your needs.

Summary

Excel gives you more options for working with tables and lists in Subtotal – whether as a function or as a tool. Es­pe­cially with complex data volumes, this helps you clear things up and gives you in­ter­est­ing in­form­a­tion.

Go to Main Menu