Updated May 5, 2023
Excel SUBTOTAL Function (Table of contents)
SUBTOTAL in Excel
- A subtotal function is an inbuilt function in Excel that is categorized under the math/trig function.
- Subtotal will not just total the numbers in a defined range of cells; it will help out by performing different arithmetic operations.
- SUBTOTAL is versatile. You can use it to average, sum up, count a bunch of cells & other calculations.
Returns a subtotal in a database or list, i.e., finding out the subtotal of a given range of cells. It performs a specified calculation for a given set of values.
SUBTOTAL Formula in Excel
The formula for the SUBTOTAL function is as follows:
SUBTOTAL(function_num, ref1, [ref2],…)Where
Function_num or operation code: It indicates which function should be used to calculate the subtotals within a given list. It is a type of mathematical operation that you like to perform.
A function_num argument is applied based on the below mentioned two criteria or methods.
- Include hidden values When the function_num argument is between 1-11, the SUBTOTAL function will include the hidden values.
- Ignore hidden values When the function_num argument is between 101-111, the SUBTOTAL function will exclude or ignore the hidden values. It will find values only invisible rows that ignore hidden values in the calculation.
Includes hidden values
Excludes hidden values
|1||101||AVERAGE||It calculates the Average of a specified range.|
|2||102||COUNT||It will Count the number of cells that contain numeric values.|
|3||103||CONTACT||It will Count non-empty cells in the specified range.|
|4||104||MAX||It will find out the largest value in the specified range.|
|5||105||MIN||It will find out the smallest value in the specified range.|
|6||106||PRODUCT||It calculates the product of cells in the specified range.|
|7||107||STDEV||It estimates Standard Deviation in the specified range.|
|8||108||STDEVP||It calculates Standard Deviation based on the entire population.|
|9||109||SUM||It calculates the Sum of the specified range.|
|10||110||VAR||It estimates variance in the specified range.|
|11||111||VARP||It estimates variance based on the entire population.|
ref1, [ref2]: One or more references to cells containing the values that the calculation is to be performed for subtotal.
How to Use the SUBTOTAL Function in Excel?
Let’s look at how the SUBTOTAL function works in Excel.
Example #1 – SUBTOTAL Formula for values Hidden using Excel Autofilter or Rows Hidden by a filter
The table contains Quarterly Sales Data in the below-mentioned example, where individual quarters are in column E & sales data in column F.
Sum function is applied in cell “F16” i.e. =SUM(F4:F15).
It returns or results in a value of 1184.
The SUM function returns the same value. i.e. 1184, instead of 194 for Q4 data, if rows are hidden by a filter (Below mentioned screenshot).
If I want the Correct SUM value of Q4 data only, then I need to use the SUBTOTAL function.
Before applying the SUBTOTAL function, Under the data toolbar, apply a filter for the header row.
Let’s calculate specifically Q1 or Q2 or Q3 or Q4 sales data individually for filtered data.
Use 109 as a function_num argument in the SUBTOTAL function, to Sum up the data. i.e. =SUBTOTAL(109,C17:C28)
The SUBTOTAL function ignores rows hidden by a filter and calculates the correct result.
Here subtotal value changes dynamically according to the filter; it will find a sum of values in visible rows only; the SUBTOTAL function neglects hidden rows. (Below mentioned, e.g.)
Example #2 – SUBTOTAL Function for manually Hidden Rows
In the Excel sheet, row no 15, 16, 19, and 20 have been hidden using the row formatting option by highlighting these rows, right-clicking with the mouse, and selecting Hide.
A subtotal function is used in cell C23 of the spreadsheet to calculate the sum of visible cells.
We have to Use 109 as a function_num argument in the SUBTOTAL function, to Sum up the data.
Here, the SUBTOTAL function ignores manually rows hidden and calculates the correct result.
It will find a sum of values in visible rows only; the SUBTOTAL function neglects hidden rowsExample #3 – SUBTOTAL Function for normal value
As all of the cells in the range of quarterly sales figures are visible, none of them is filtered, or rows are hidden; it includes all the values.
In the below-mentioned example, multiple subtotal functions are applied.
In a cell, C14, C15 & C16 SUBTOTAL function is applied.
To calculate the SUM value, Function number 9 or 109 is used in a subtotal function where It calculates the Sum of a specified range, i.e. =SUBTOTAL (9, C4:C11)
It will give us the sum of all values in C4:C11, provided none are filtered & rows are hidden in that specified range.
To calculate the MIN value, Function number 5 or 105 is used in a subtotal function where It will find out the smallest value in the specified range. In a cell, C15, a SUBTOTAL function is applied, i.e. =SUBTOTAL(5,C4:C11)
It will find out the smallest value in the specified range, i.e. C4:C11
To calculate the MAX value, Function number 4 or 104 is used in a subtotal function where It will find out the largest value in the specified range. In a cell, C16, a SUBTOTAL function is applied, i.e. =SUBTOTAL(4,C4:C11)
It will find out the largest value in the specified range, i.e. C4:C11.
Things to Remember about the SUBTOTAL Function
- You can apply the SUBTOTAL function to find the sum of filtered values.
- A SUBTOTAL function is used to ignore values in hidden rows.
- Function _ num argument value should not be greater than 11 or less than 1, and similarly should not be greater than 111 or less than 101; otherwise, it will give #VALUE! error.
- A SUBTOTAL function is applicable only for the numeric value.
- If there are any subtotals present in the SUBTOTAL range, they will be neglected, i.e. If any already existing SUBTOTAL formulas are present in the input range of another SUBTOTAL formula, then these values are neglected by subtotal function during the calculation so that double counting is avoided & it prevents the error of double counting.
- You can use a SUBTOTAL function to dynamically summarize data in Excel.
The subtotal function ignores blank cells and cells containing non-numeric values when calculating data.
This has been a guide to SUBTOTAL. Here we discuss the SUBTOTAL Formula and how to use the SUBTOTAL Function along with excel examples and downloadable excel templates. You may also look at these useful functions in Excel –