Sum Multiple Columns Dynamically Across Rows in Google Sheets

Are you tired of manually summing multiple columns across rows in Google Sheets? Look no further! In this article, I’ll share a simple and effective solution that will save you time and effort.

The Challenge

Imagine you have a dataset in Google Sheets with several columns of daily data. The challenge arises when you want to calculate the sum of multiple columns, but the columns vary from row to row. So how do you tackle this problem? Let’s dive in!

Example Dataset

Before we dig into the solution, let’s take a look at a sample dataset to better understand the concept. Here’s what it looks like:

Sum Multiple Columns Dynamically in Google Sheets

In this dataset, we want to create a formula in cell N2 that can dynamically sum multiple columns.

The Solution

To achieve our goal, we’ll use two cells to specify the starting and ending column numbers for the sum. Let’s call these cells “FROM” and “TO”.

For example, if we want to sum columns 5 to 7, we would use the formula: E2+E3+E4+F2+F3+F4+G2+G3+G4.

But how do we make this formula dynamic? Here’s what you need to do:

  1. In cell H2, enter the starting column number.
  2. In cell I2, enter the ending column number.
  3. In cell F1, enter the following formula:
=QUERY({A1:E},"Select "&H2&" label "&H2&"'Total'")

In this formula, A1:E is the data range. The starting and ending column numbers are referenced using H2 and I2, respectively. The “Total” label is added to the result using the label clause in the query.

To generate the dynamic column numbers in the formula above, we’ll use a helper cell, let’s call it K1. In K1, enter the following formula:

=ArrayFormula(textjoin("+ ",TRUE,("Col"&row(indirect("A"&H2&":A"&I2)))))

This formula generates a text string that represents the column IDs separated by the “+” operator. This string is then used as the query argument in the formula in cell F1.

And voila! You now have a dynamic formula that can sum multiple columns across rows in Google Sheets.

Key Formula Logic and Explanation

If you’re curious about the inner workings of the formula in cell K1, let me break it down for you:

  1. The INDIRECT function is used to generate a range reference based on the starting and ending column numbers.
  2. The ROW function extracts the row number of each column in the range.
  3. The ARRAYFORMULA function allows the formula to work on multiple rows at once.
  4. The TEXTJOIN function combines the column IDs with the “+” operator, creating the query argument.

For a detailed step-by-step explanation of this formula, you can refer to this guide.

That’s it! You now have the knowledge to dynamically sum multiple columns across rows in Google Sheets. Say goodbye to manual calculations and save precious time. Happy spreadsheeting!

Crawlan.com

Related posts