HomeGoogle DocsSpreadsheetHow to Use Dynamic Ranges in SUMIF Formula in Google Sheets

How to Use Dynamic Ranges in SUMIF Formula in Google Sheets

Published on

We can use the Offset function to get dynamic ranges in SUMIF in Google Sheets. In this tutorial, we can learn that trick.

By the term “dynamic ranges,” I mean the range in a formula that accommodates values in any rows inserted later, just above or below the formula range.

So, this time, in this advanced SUMIF tutorial, you can learn how to use dynamic ranges in the SUMIF formula in Google Sheets.

How to Apply Dynamic Ranges in SUMIF Formula in Google Sheets

Let’s follow the below approach/steps to learn this.

  1. Sample Data.
  2. Basic SUMIF formula.
  3. Creating a dynamic range for the SUMIF formula above.
  4. Formula Explanation.

1. Sample Data

Here is my sample data for learning the dynamic ranges in a formula.

sample data for learning dynamic ranges in SUMIF

Here is the basic SUMIF formula.

2. Basic SUMIF Formula

=sumif(D2:D8,"Safety Helmet",H2:H8)

In this formula, D2:D8 is the range, “Safety Helmet” is the criterion, and H2:H8 is the Sum Range.

Syntax: SUMIF(range, criterion, [sum_range])

Result: 120.00

Now see what happens when you insert new rows above and bottom of our selected ranges in SUMIF.

Sumif formula excludes newly inserted rows above and bottom

The formula changes the ranges from D2:D8 to D3:D9 and H2:H8 to H3:H9. It excludes the newly added rows.

You can try using the Dollar Symbol to freeze the rows, as well as columns. But that doesn’t affect inserted rows.

3. How to Create a Dynamic Range for the Sumif Formula Above?

We can use Offset based dynamic ranges in SUMIF to overcome the above problem in Google Sheets.

In the above SUMIF formula, instead of the range D2:D8, we can use the below OFFSET formula.

offset(D1,1,0):offset(D9,-1,0)

For H2:H8, the alternative offset range is;

offset(H1,1,0):offset(H9,-1,0)

Now you can see how I’m going to apply dynamic ranges in the SUMIF formula in Google Sheets. Here is that formula.

=sumif(offset(D1,1,0):offset(D9,-1,0),"Safety Helmet",offset(H1,1,0):offset(H9,-1,0))

If you use this formula in the above example, there is no need for you to change the formula range manually.

When you insert new rows just above or below the formula range, they will be automatically included in the calculation.

4. Sumif Dynamic Range Formula Explanation

Before going to the formula explanation part, see what happens when I insert new rows above and below our data range.

dynamic sumif range formula explanation in Google Sheets

Here our dynamic SUMIF formula using the Offset function returns the correct result in cell H14, whereas the usual SUMIF formula in cell H13 skips the inserted rows in the calculation.

There is nothing special in this dynamic formula. You are just replacing the range with the Offset.

See the Offset syntax.

OFFSET(cell_reference, offset_rows, offset_columns

Once again, see our basic/usual SUMIF formula and ranges.

=sumif(D2:D8,"Safety Helmet",H2:H8)

In SUMIF using Offset as ranges, D2:D8 is replaced by the below offset formula.

offset(D1,1,0):offset(D9,-1,0)

Instead of D2, here within Offset, I’ve used D1 as the cell reference and offset 1.

So here also, the cell reference is D2.

But the advantage is you can insert any number of rows just above D2. The Offset would include this in the dynamic ranges in SUMIF.

Similarly, in SUMIF, another cell reference is D8. But in dynamic SUMIF using Offset, it’s D9 and Offset -1.

So again, here also, the actual cell reference is pointing to D8.

The above points apply to the range H2:H8 also.

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.

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

SUMPRODUCT Differences: Excel vs. Google Sheets

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

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

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.