SUBTOTAL
The SUBTOTAL
function in Google Sheets is a powerful tool to calculate subtotals for a vertical range of cells using specified aggregation functions. Whether you need to calculate sums, averages, counts, or other types of aggregations, the SUBTOTAL
function simplifies the task. Dive into our comprehensive guide to master its application.
Function Syntax and Parameters
Syntax: SUBTOTAL(function_code, range1, [range2, ...])
Parameters:
function_code
: A number that specifies the aggregation function to be used. Here are some commonly used function codes:1
: AVERAGE2
: COUNT3
: COUNTA4
: MAX5
: MIN6
: PRODUCT7
: STDEV8
: STDEVP9
: SUM10
: VAR11
: VARP
range1
: The first column or range to consider for calculations.range2, ...
: [Optional] Additional columns or ranges to consider.
Step-by-Step Tutorial
-
Using
SUBTOTAL
with different aggregation functions:- Example 1: To calculate the sum of numbers in the range
A1:A10
, use=SUBTOTAL(9, A1:A10)
. - Example 2: To count the non-blank cells in the range
C1:C5
, use=SUBTOTAL(3, C1:C5)
.
- Example 1: To calculate the sum of numbers in the range
-
Using
SUBTOTAL
with multiple ranges:- Example: If you want to calculate the average and sum of numbers in both the ranges
B1:B5
andD1:D5
, you can use=SUBTOTAL(1, B1:B5, D1:D5)
and=SUBTOTAL(9, B1:B5, D1:D5)
respectively.
- Example: If you want to calculate the average and sum of numbers in both the ranges
Use Cases and Scenarios
- Financial Analysis: Calculate the total sales, average expenses, or other financial metrics for a set of transactions.
- Data Analysis: Obtain various statistics such as count, sum, or average on a subset of data within a larger dataset.
- Inventory Management: Determine the total quantity, minimum stock level, or other inventory-related calculations.
Related Functions
SUM
: Calculate the sum of a range of cells.COUNT
: Count the number of cells that contain numbers within a range.AVERAGE
: Calculate the average of a range of cells.MAX
: Find the largest value in a set.MIN
: Find the smallest value in a set.