---
title: "Custom function for get subtotals for each group in Google Sheets using Google Apps Script"
author: "Martin Hawksey"
date: 2023-02-14T21:48:28+00:00
canonical_url: https://pulse.appsscript.info/p/2023/02/custom-function-for-get-subtotals-for-each-group-in-google-sheets-using-google-apps-script/
markdown_url: https://pulse.appsscript.info/p/2023/02/custom-function-for-get-subtotals-for-each-group-in-google-sheets-using-google-apps-script.md
categories:
  - "Intermediate"
  - "Sheets"
  - "Solutions"
tags:
  - "@max__makhrov"
  - "max-makhrov"
  - "Medium"
featured_image: https://pulse.appsscript.info/files/2023/02/1oNFnzxlXkE_ynAcg_FkXNw.png
description: "The code speaks for itself in this post from Max Makhrov in which he shows how to create a custom function for Google Sheets to subtotal groups of columns. There is some impressive data manipulation/reshaping going on in the function and some nice use of using arrays in formula created with brackets { }. Some of the code is also written with OpenAI/ChatGPT (I'm guessing anything with a for loop). The icing on top is the conditional formatting for group totals. Follow the source link for all the code. "
---

# Custom function for get subtotals for each group in Google Sheets using Google Apps Script

![Custom function for get subtotals for each group in Google Sheets using Google Apps Script](https://pulse.appsscript.info/files/2023/02/1oNFnzxlXkE_ynAcg_FkXNw.png)

> [https://max-makhrov.medium.com/subtotals-for-each-group-in-google-sheets-8337054f9ca9](https://max-makhrov.medium.com/subtotals-for-each-group-in-google-sheets-8337054f9ca9)
> You get subtotal sums for each of the selected columns.

The code speaks for itself in this post from Max Makhrov in which he shows how to create a custom function for Google Sheets to subtotal groups of columns. There is some impressive data manipulation/reshaping going on in the function and some nice use of [using arrays in formula**](https://support.google.com/docs/answer/6208276?hl=en-GB) created with brackets `{ }`. Some of the code is also written with OpenAI/ChatGPT (I’m guessing anything with a `for` loop). The icing on top is the conditional formatting for group totals. Follow the source link for all the code.

Source: *[Subtotals for each group in Google Sheets*](https://max-makhrov.medium.com/subtotals-for-each-group-in-google-sheets-8337054f9ca9)

---

*Published by [Martin Hawksey](https://pulse.appsscript.info/p/author/admin/) on [Pulse](https://pulse.appsscript.info/). Original article: [https://pulse.appsscript.info/p/2023/02/custom-function-for-get-subtotals-for-each-group-in-google-sheets-using-google-apps-script/](https://pulse.appsscript.info/p/2023/02/custom-function-for-get-subtotals-for-each-group-in-google-sheets-using-google-apps-script/)*
