Excel SUBTOTAL Function
Unlike SUM, AVERAGE, COUNTA and other functions which only do one thing, the SUBTOTAL function is versatile and can perform different arithmetic and logical operations, such as calculating a sum or average, finding the minimum or maximum value, getting the standard deviation, and more (see the table below the argument function_num). Also, SUBTOTAL is more flexible since it can either include or exclude hidden values.
Syntax
=SUBTOTAL(function_num, ref1, [ref2], ...)
Arguments
- function_num (required): The number 1-11 or 101-111 that specifies the mathematical operation you want to use in the calculation:
- 1 – 11: Include manually hidden rows;
- 101 – 111: Ignore manually hidden rows.
Function_num Function Description Include
hiddenIgnore
hidden1 101 AVERAGE Calculates the average of numbers 2 102 COUNT Counts cells that contain numeric values 3 103 COUNTA Counts non-blank cells 4 104 MAX Returns the maximum value 5 105 MIN Returns the minimum value 6 106 PRODUCT Calculates the product of numbers 7 107 STDEV Calculates the standard deviation based on a sample 8 108 STDEVP Calculates the standard deviation based on the entire population 9 109 SUM Calculates the sum of numbers 10 110 VAR Estimates the variance based on a sample 11 111 VARP Estimates the variance based on the entire population
- ref1 (required): A named range or reference for which you want the subtotal.
- [ref2], ... (optional): Up to 254 other named ranges or references to subtotal.
Return Value
The SUBTOTAL function returns a numeric value.
Function Notes
- SUBTOTAL ignores values in filtered-out rows, regardless of function_num.
- SUBTOTAL with function_num of 101-111 ignores values in hidden rows, but not in hidden columns. Values in hidden columns are always included.
- SUBTOTAL ignores other SUBTOTAL formulas that exist in ref1, ref2, … to avoid double-counting.
- SUBTOTAL will return the #DIV/0! error if the function has to perform a division by zero (0).
- SUBTOTAL will return the #VALUE! error if:
- function_num is any number other than 1-11 or 101-111;
- Any of the ref arguments contains a non-numeric value;
- Any of the ref arguments contains a 3-D reference.
Example
Supposing you have an inventory sheet as shown above, to get the total number of items in the sheet, please copy or enter the formula below in cell G5, and press Enter to get the result:
=SUBTOTAL(3,B4:B14)
To get the total units of all the items in both Store I and Store II in the sheet, please copy or enter the formula below in cell G8, and press Enter to get the result:
=SUBTOTAL(9,D4:D14,E4:E14)
To know the average price of the items in the sheet, please copy or enter the formula below in cell G11, and press Enter to get the result:
=SUBTOTAL(1,C4:C14)
√ Note: To make the results show properly in currency format as shown above, you should apply the Format Cells feature: Select the cells where you want to apply the feature, then press Ctrl + 1. Under the tab Number in the pop-up Format Cells dialog, choose Currency, and set the decimal places, symbol and format for negative numbers in the right section:
Related functions
The Excel AGGREGATE function returns an aggregate of calculations such as SUM, COUNT, SMALLL and so on with the option to ignore errors and hidden rows.
The Best Office Productivity Tools
Kutools for Excel - Helps You To Stand Out From Crowd
Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...
Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)
- One second to switch between dozens of open documents!
- Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
- Increases your productivity by 50% when viewing and editing multiple documents.
- Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Edge and Firefox.