Use the SUBTOTAL function to summarize amounts, and exclude filtered or hidden rows. For Excel 2010 and later AGGREGATE function is also available, and has more options and functions.
Use the SUBTOTAL function to exclude filtered or hidden rows when calculating. This video shows how to choose different functions for the SUBTOTAL function, from a drop down list on the worksheet. There are details on the SUBTOTAL function, below the video.
In Excel, you might have a long list of orders with a grand total at the end. If you filter the Region column, so the list only shows one region’s sales, you’d like the total to include only those items.
If you used the SUM function in the grand total cell, the result won’t change if a filter is applied. This list is filtered to show orders from the West Region. At a glance, you can see that the Grand Total is much higher than the records listed. There are only 3 orders visible, but the order count is calculated as 49.
Instead of SUM or COUNT, use the SUBTOTAL function, and only the filtered rows will be included in the grand total.
A quick way to create a SUBTOTAL formula is to:
Because the list is filtered, a SUBTOTAL formula is inserted, instead of a SUM formula.
Within the brackets for the SUBTOTAL function there are two arguments, separated by a comma (or a semi-colon, depending on your regional settings).
The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. When you type the opening bracket for the SUBTOTAL function, the list of functions will appear.
There are 11 functions, listed alphabetically, with numbers 1-11, and again, with numbers 101-111.
The table below shows the 11 functions that you can use as the first argument in the SUBTOTAL function. Each function has two numbers:
Note that the list is alphabetical, so that might help you remember the number that you use most often.
|AVERAGE||1 or 101|
|COUNT||2 or 102|
|COUNTA||3 or 103|
|MAX||4 or 104|
|MIN||5 or 105|
|PRODUCT||6 or 106|
|STDV||7 or 107|
|STDEVP||8 or 108|
|SUM||9 or 109|
10 or 110
|VARP||11 or 111|
The two number ranges contain the same functions, but there is one key difference between them.
Note: Rows that you format with zero height WILL NOT be included in either type of subtotal.
There are more SUBTOTAL examples on the following pages:
For Excel 2010 and later AGGREGATE function is also available. It is similar to SUBTOTAL, but has more options and functions.
Excel also has a Subtotals feature, that groups the items in a list, and adds one or more subtotal rows.
Last updated: July 27, 2018 8:31 AM