SUBTOTAL(function_code, range1, [range2, ...])One free generation or explanation per browser, shared across Excel and Google Sheets. Account usage limits apply afterward.
function_code:
A number that specifies which function to use for the subtotal calculation. It determines the type of aggregation (e.g., SUM, AVERAGE, COUNT) and whether to include hidden rows.
range1:
The first range of cells that you want to include in the subtotal calculation.
range2:
An optional additional range of cells that you want to include in the subtotal calculation. You can include multiple ranges as needed.
The SUBTOTAL function in Google Sheets is a versatile tool used to perform calculations on a range of data while allowing for filtering and excluding hidden rows. It can be used for various operations such as SUM, AVERAGE, COUNT, and more, making it an essential function for data analysis and reporting.
In simpler terms, SUBTOTAL allows you to calculate summary statistics for a dataset while taking into account any filters applied to that dataset.
Imagine you are managing a sales report stored in a Google Sheets document:
| SaleID | ProductName | Quantity | Price |
|---|---|---|---|
| 1 | Widget A | 3 | 25.00 |
| 2 | Widget B | 5 | 30.00 |
| 3 | Widget C | 2 | 15.00 |
| 4 | Widget A | 4 | 25.00 |
| 5 | Widget B | 1 | 30.00 |
You want to calculate the total sales amount while being able to filter the data by product.
To achieve this, you would use the SUBTOTAL function as follows:
=SUBTOTAL(109, D2:D6)In this formula:
109 is the function number that specifies the operation (in this case, SUM while ignoring hidden rows).D2:D6 is the range of cells containing the Price values that you want to sum.When you apply the SUBTOTAL formula to the Sales Data Table, the output would show the total sales amount. If you filter the table to show only Widget A, the SUBTOTAL will automatically adjust to reflect only the visible rows:
| ProductName | Total Sales |
|---|---|
| Widget A | 175.00 |
If you were to apply a filter to show only Widget B, the result would change accordingly:
| ProductName | Total Sales |
|---|---|
| Widget B | 60.00 |
SUBTOTAL is beneficial because it allows for dynamic calculations that respond to filtering, making it ideal for analyzing large datasets. It simplifies the process of summarizing data without needing to adjust formulas manually when rows are hidden or filtered out.
SUBTOTAL is an essential function for anyone working with data in Google Sheets, providing a robust way to enhance data analysis and reporting capabilities.
Happy spreadsheeting!
You have a sales data table with monthly sales figures in Column B. Using the SUBTOTAL formula, you can calculate the sum of visible sales data after applying filters, allowing for dynamic analysis of sales performance without affecting hidden rows.
Sign up for Better Analyst and get unlimited AI-powered formula generation, explanations, and advanced data analysis.
Browse our complete library of Google Sheets formula guides
Compare your options
Open a neutral research prompt in the AI tool you already use. Compare capabilities, limitations, and fit before you choose.
AI answers can be incomplete. Check source links, current pricing, and product documentation before deciding.