This page describes the Excel Subtotal function. However, Excel also has a Subtotal command that inserts subtotals into a data table.For details, see the Excel Subtotal Command page.
The Excel Subtotal function performs a specified calculation (e.g. the sum, product, average, etc.) for a supplied set of values.
The syntax of the function is:
Where the arguments are as follows:
An integer that denotes the calculation type (e.g. sum, average, etc.).(See the table below for possible values for function_num).
|ref1, [ref2], ...||-||(Blank cells and cells containing non-numeric values are ignored in the calculation).|
(include hidden values)
(ignore hidden values)
The possible values for the function_num argument are shown in Table 1 (see rightabove).
For each arithmetic operation, there is an option to ignore or to include hidden values in the calculation. Note that:
The following examples all use a simple company spreadsheet, that shows monthly sales figures, between January and March, for 3 teams.
In cells C12 and C13 of the spreadsheet below, the Subtotal function is used to calculate the sum and the average monthly sales per team. As all of the cells in the range of sales figures are visible, the calculations include all values in the sales column:
Note that, in the example above, as all cells are visible, we could have set the function_num argument to be either 9 or 109 for the sum, and to be either 1 or 101 for the average calculation. Both options would give the same two results.
In this example, the teams column of the spreadsheet has been filtered, using the Excel Autofilter, to show Team 1 only. In this case, the Subtotal function's calculations will be for the visible cells only (i.e. for Team 1 only):
Note that, in the example above, because the rows for Teams 2 & 3 have been filtered out, using the Excel Autofilter, we could have used a function_num argument of either 9 or 109 for the sum and a function_num argument of either 1 or 101 for the average. Both options would perform the calculation on the visible cells only.
In the spreadsheet below, rows 3, 4, 6, 7, 9, and 10 have been hidden using row formatting. I.e. by highlighting these rows, right clicking with the mouse and selecting Hide.
Once again, the Subtotal function has been used in cells C12 and C13 of the spreadsheet, to calculate the sum and average of the monthly sales across the visible teams.
Because the non-visible rows have been hidden using the row formatting option, if you want to only include the visible cells in the calculations, it is necessary to set the function_num argument to the value 109 for the sum calculation, and to the value 101 for the average calculation.
Further details and examples of the Excel Subtotal Function are provided on the Microsoft Office website.
If you get an error from the Excel Subtotal function this is likely to be one of the following:
|#VALUE!||-||Occurs if the supplied function_num argument is not one of the permitted values (an integer between 1 & 11 or between 101 & 111).|
|#DIV/0!||-||Occurs if required calculation involves a division by zero (e.g. finding the average, standard deviation or variance for a range of cells that do not contain any numeric values).|