HomeGoogle DocsSpreadsheetReverse Running Total in Google Sheets (Array Formula)

Reverse Running Total in Google Sheets (Array Formula)

Published on

I have an array formula to get the reverse running total in Google Sheets.

When you have your data sorted from newest to oldest, you may find this very useful over the running total (cumulative sum).

For example, let’s consider the wheat production in Australia from 2010 to 2019 (data from wiki).

In Google Sheets, we can arrange the data in two columns as below.

Reverse Running Total in Google Sheets

Columns A and B contain years and the quantities of wheat production (million metric tonnes), respectively.

What is important here is the data arranged in descending order (newest to oldest) by the year in column A.

See the values in the cumulative sum columns C and D.

How do they differ?

In column C, you can see the running total calculated from top to bottom, whereas, in column D, the same calculation is from bottom to top.

From column D, you can understand the cumulative wheat production up to that year from each row.

How to calculate the reverse running total in Google Sheets as above in column D?

If you prefer a non-array formula, you can use the below formula in cell D2 and drag it down until row#11.

=sum($B$2:$B)-sum(arrayformula(n($B$1:B1)))

But I do have an array formula.

Array Formula for Reverse Running Total in Google Sheets

We will use a SUMIF array formula here.

Syntax:

ArrayFormula(SUMIF(range, criterion, [sum_range]))

We have the sum_range to calculate the reverse cumulative sum, which is B2:B. What about range and criterion?

You can find that within the formula below.

Empty the entire column D because we want to insert an array formula in cell D1, which requires an empty column to work without the #REF error.

The below formula is for cell D1.

={"Reverse Running Total";ArrayFormula(If(B2:B="",,SUMIF(sort(row(A2:A),1,0),"<="&sort(row(A2:A),1,0),B2:B)))}

The above array formula will return the reverse running total in Google Sheets for the range B2:B.

It has a sheer benefit over its counterpart (non-array).

It uses an open range B2:B. So it will return the reverse running total in all the rows in column D. But, there should be values in column B. Blank rows will be ignored.

Learn the range and criterion used in the formula from the explanation part below.

Update: This will also work ={"Reverse Running Total";ArrayFormula(If(B2:B="",,SUMIF(row(A2:A),">="&row(A2:A),B2:B)))}. But the explanation will be based on the formula above.

Formula Explanation

Let’s remove the unwanted string from the formula, i.e., the header “Reverse Running Total,” and make the ranges closed. Then use a helper column.

So we can shorten the SUMIF formula and make it easily readable.

=ArrayFormula(If(B2:B11="",,SUMIF(C2:C11,"<="&C2:C11,B2:B11)))
Reverse Running Total Using Helper Column for Explanation

We can split the formula into three parts.

Part 1

ArrayFormula – To help the SUMIF to return an array result. The IF also requires this.

ArrayFormula(

Part 2

IF – To limit the output in such rows that contain values in column B.

If(B2:B11="",,

Part 3

SUMIF – To return the reverse running total in Google Sheets.

SUMIF(C2:C11,"<="&C2:C11,B2:B11)

Note:- The cell range C2:C11 is a temporary helper range for the formula explanation. Please refer to the image above. In the main formula, we have used sort(row(A2:A),1,0) instead.

This formula requires a detailed explanation to understand how the SUMIF returns reverse running total in Google Sheets.

Let’s test the formula in a particular row, for example, in row # 5.

=SUMIF(C2:C11,"<="&C5,B2:B11)
Cumulative Sum from Bottom to Top

The formula returns the total wheat production in Australia from 2010 to 2016 (highlighted cells).

Because the criterion, i.e., C2:C11<=C5, in column C matches in that highlighted rows.

Resources:

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.

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

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

More like this

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

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

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.