HomeGoogle DocsSpreadsheetAdd Total Based on Each Change in a Column Value in Google...

Add Total Based on Each Change in a Column Value in Google Sheets

Published on

The Subtotal command in Excel enables users to add group total based on each change in a column value. At present, Google Sheets has no similar option.

In Google Sheets, the possibly best way to achieve a similar result is by using Pivot Table.

You can optionally use the QUERY function if you want the group-wise total in Google Sheets.

But all these functions and commands populate the data in a separate range in Google Sheets.

A command similar to Subtotal in Excel, as a side note SUBTOTAL function is different, is what I am missing in Google Sheets.

In a limited way, we can overcome this with a custom formula.

How to Add Total Based on Each Change in a Column Value

Sample Data:

Example to Total on Each Changes in a Column Value

In this Google Sheets example, there are four fruit items in column A. You can call it four groups.

To add the total based on each change in a column value, we require the items sorted, and the above sample data fulfills this criterion.

You can see the total in column D based on each change of values in column A.

To add such totals, I’ve applied a custom Google Sheets formula in cell D2 and then copy-pasted it down.

Formula:

=if(A2<>A3,sum($C$1:C2)-sum($D$1:D1),"")

Note: I have array formulas to achieve the same output. Get that here – Sum Column B When Value in Column A Changes in Google Sheets.

I know I should explain this formula so you can use it on any column in your original data.

Formula Explanation Part:

As I told you, it’s not an array formula. So, you should copy-paste it down.

For explanation purposes, I’m taking you to the formula in cell D10. See the screenshot.

subtotal grouping in google sheets

The formula in D10 tests the value in A11 whether it’s equal to the value in A10.

If the A11 value is different, in D10, the IF logical function would execute the SUM function, else return a blank.

The SUM function sums column C up to C10 and then minus any value in column D up to D9. See the above screenshot to understand it. That’s all.

The only drawback of the above formula approach to adding total based on each change in a column value is that it’s not an array formula that spills down.

Additional Info.: If you want the subtotal or grouped total, the below Query formula is enough. It populates the summary in a new range.

=query(A1:C,"select A, sum(C) where A<>'' group by A", 1)

That’s all. Thanks for the stay. Enjoy!

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

SUMPRODUCT Differences: Excel vs. Google Sheets

The core purpose of the SUMPRODUCT function remains consistent across both Excel and Google...

Sum Values by Month and Category in Excel

With the help of EOMONTH, UNIQUE, and SUMIFS functions in Excel, you can efficiently...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

2 COMMENTS

  1. Hi Prashanth,

    You have rectified one of my earlier Sheets. Now, it has suddenly stopped working. I did try my level best to solve it, but unable to do that. I am sharing the link with you and highlighting the formula cell. Please help.

    • Hi, Zyshan,

      The formulas have no issue.

      The issue is due to column G (Quantity). Test with =ISNUMBER(G2). The formula would return FALSE. This means the column contains TEXT.

      You should check your source (as you are importing) why the values are text strings instead of numbers. Correct it.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.