HomeGoogle DocsSpreadsheetExtract Total and Grand Total Rows From a Pivot Table in Google...

Extract Total and Grand Total Rows From a Pivot Table in Google Sheets

Published on

It’s almost impossible to extract total and grand total rows from a Pivot table report using the GETPIVOTDATA function in Google Sheets. But there is an alternative formula.

Of course, to dynamically pull aggregated values from a Pivot table, including from a total row, you can use the GETPIVOTDATA function. 

But with this function, you can’t pull an entire total row without nesting it.

For example, see the below nested GETPIVOTDATA formula in cell E12 and the pivot table report in A1:D12.

={"Grand Total",GETPIVOTDATA("Sum of Total Sales",A1),GETPIVOTDATA("Average of Total Sales",A1)}
Extract Total and Grand Total Rows From a Pivot Table

The formula successfully extracts the grand total row.

But what about including the subtotal rows? I mean the “Jeanne Total” and “Matt Total” rows.

The GETPIVOTDATA nested formula will become very complicated. Please see the example below.

={"Jeanne Total",GETPIVOTDATA("Sum of Total Sales",A1,"Name","Jeanne"),GETPIVOTDATA("Average of Total Sales",A1,"Name","Jeanne");{"Matt Total",GETPIVOTDATA("Sum of Total Sales",A1,"Name","Matt"),GETPIVOTDATA("Average of Total Sales",A1,"Name","Matt")};{"Grand Total",GETPIVOTDATA("Sum of Total Sales",A1),GETPIVOTDATA("Average of Total Sales",A1)}}

You can ignore this formula. You can’t call this a dynamic formula because, for each total row, you must nest the formula.

That means you can’t use the GETPIVOTDATA function dynamically to extract the individual totals and grand total rows from a Pivot table.

Instead, you can use a FILTER + SEARCH combo, which is dynamic.

When the source changes, the total rows may move up or down. My formula is ready to accommodate those changes.

Let’s consider a small dataset (sales report of two employees).

Sales Report Mock-up for Pivot Table

Here are the Pivot table settings used to generate the above Pivot table report.

Total Settings for a Pivot Table to Extract Total Rows

As a side note, to access the Pivot table editor, go to the Insert menu Pivot table.

Formula to Extract the Total Rows From a Pivot Table Report in Google Sheets

The following Filter + Search combo will pull the subtotal and total rows from the above Pivot table.

=filter(A1:D,search("Total",A1:A)>1)

It’s a very clean formula compared to the GETPIVOTDATA one above. It’s also dynamic.

Formula Output:

Jeanne Total$15,200.00$3,800.00
Matt Total$14,000.00$3,500.00
Grand Total$29,200.00$3,650.00

Why should I call it dynamic?

For example, assume you have added one more employee to your sales report.

The formula will include that person’s total also in the extracted output.

How to Use the Filter + Search Combo in Pivot Table to Pull Data

The FILTER function is handy to use to filter a table with conditions. You can use this function in a Pivot table too.

FILTER(range, condition1, [condition2, ...])

I have used the Search formula to feed the Filter criterion/condition1. It is because I want to do a partial match.

I want to filter rows in the Pivot table column A that contain the string ‘Total.’

That’s why I have used the Search function within Filter.

The Search function will return a numeric number if the string ‘Total’ is available in a row. So the criterion will be;

search("Total",A1:A)>1

Some of you may ask about the possibility of using any wildcard characters within the Filter. The answer is NO. That’s why I have used the Search function.

That’s all about extracting total rows dynamically from a Pivot table in Google Sheets.

I hope you have enjoyed this tutorial. See you next time with another Google Sheets tutorial.

Similar Tutorials:

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.

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

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;...

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,...

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.