Google Sheets SUBTOTAL Function: Syntax, Examples & Tips

The SUBTOTAL function calculates a specified aggregate (like SUM or AVERAGE) for a range, allowing for filtered data to be included or excluded.
Google Sheets
SUBTOTAL(function_code, range1, [range2, ...])

One free generation or explanation per browser, shared across Excel and Google Sheets. Account usage limits apply afterward.

On this page
  1. Parameters
  2. What is a SUBTOTAL?
  3. A Practical Example
  4. SUBTOTAL Formula
  5. Result of the Formula
  6. Why Use SUBTOTAL?
  7. Key Takeaways:
  8. Example use case

Parameters

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.

What is a SUBTOTAL?

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.

A Practical Example

Imagine you are managing a sales report stored in a Google Sheets document:

Sales Data Table:

SaleIDProductNameQuantityPrice
1Widget A325.00
2Widget B530.00
3Widget C215.00
4Widget A425.00
5Widget B130.00

You want to calculate the total sales amount while being able to filter the data by product.

SUBTOTAL Formula

To achieve this, you would use the SUBTOTAL function as follows:

Google Sheets
=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.

Result of the Formula

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:

ProductNameTotal Sales
Widget A175.00

If you were to apply a filter to show only Widget B, the result would change accordingly:

ProductNameTotal Sales
Widget B60.00

Why Use SUBTOTAL?

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.

Key Takeaways:

  • SUBTOTAL: A powerful function that performs calculations on a range while considering filtered data.
  • Versatile: Supports various operations such as SUM, AVERAGE, COUNT, and more.
  • Dynamic: Automatically adjusts calculations based on visible rows, enhancing data analysis.
  • Common Use Cases: Ideal for sales reports, financial summaries, and any scenario where filtered data analysis is necessary.

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!

Example use case

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.

Need more help with Google Sheets formulas?

Sign up for Better Analyst and get unlimited AI-powered formula generation, explanations, and advanced data analysis.

Explore all Google Sheets formulas

Browse our complete library of Google Sheets formula guides

Compare your options

Decide with evidence, not a sales pitch.

Open a neutral research prompt in the AI tool you already use. Compare capabilities, limitations, and fit before you choose.

  1. 01ChatGPTOpen a balanced comparison prompt in ChatGPT.
  2. 02ClaudeOpen the same research prompt in Claude.
  3. 03PerplexityResearch the comparison with linked web sources.

AI answers can be incomplete. Check source links, current pricing, and product documentation before deciding.