Sum of Matrix Rows or Columns Using SUMIF in Google Sheets

Published on

In this post — Sum of matrix rows or columns in Google Sheets — let’s look at how to get a total row or column using the SUMIF function.

You might’ve seen total rows or columns in pivot tables. But what if you’re working in a normal table or array? We can create similar total rows or columns using SUMIF, without needing to build a pivot.

Usually, to calculate the sum of matrix rows (a total column on the right of a range) or matrix columns (a total row at the bottom), we use the BYROW or BYCOL function. Earlier, we relied on MMULT, DSUM, or QUERY. I’ve already explained part of that in my post on How to Sum Each Row in Google Sheets.

But we can do the same using a clever SUMIF trick too.

You might ask — is this really necessary? Maybe not, but it’s a neat trick to know!

So let’s go through how to get the sum of matrix rows or columns using SUMIF in Google Sheets.

Can We Really Use SUMIF to Get Row or Column Totals?

You might know that the main purpose of SUMIF is to do a conditional sum.

But here, we don’t have any “conditions” — just a matrix and a goal: total up each row or column.

So how do we make that work?

SUMIF Logic for Total Rows and Columns in Google Sheets

Let’s say you have a matrix in range C3:F7.

Sample matrix in Google Sheets showing row-wise and column-wise totals added using SUMIF
image – 1

Our goal is to:

  • Get row totals in G3:G7
  • Get column totals in C8:F8

This is similar to what a pivot table might do — just manually.

In an earlier tutorial, I showed how to get totals from multiple columns using SUMIF by duplicating the range. We’re doing something similar here — except this time, we’re not using real “criteria” or a “range.”

We’re building virtual ones using ROW and COLUMN.

Let me explain.

Sum of Matrix Rows Using SUMIF in Google Sheets

We want the row totals from the matrix C3:F7, and we want to display them in G3:G7.

This matrix has 5 rows and 4 columns.

Step 1: Create a virtual “range” — a matrix of row numbers

=ArrayFormula(IF(COLUMN(C3:F3), ROW(C3:F7)))

This gives us a grid filled with the corresponding row numbers — same shape as our matrix.

3333
4444
5555
6666
7777

Step 2: Set the criteria — actual row numbers (one column only)

=ArrayFormula(ROW(C3:C7))
3
4
5
6
7

Step 3: Final formula to get row totals (in G3)

=ArrayFormula(SUMIF(IF(COLUMN(C3:F3), ROW(C3:F7)), ROW(C3:C7), C3:F7))

This gives you the sum of each row — a total column on the right of your matrix.

Sum of Matrix Columns Using SUMIF in Google Sheets

Now let’s get the column totals. We want the sum of elements in each column of C3:F7, and we’ll output that in C8:F8.

This matrix spans columns C to F and has 5 rows.

Step 1: Create a virtual “range” — a matrix of column numbers

=ArrayFormula(IF(ROW(C3:C7), COLUMN(C3:F7)))

This returns a grid where each cell holds the column number — again, matching the matrix shape.

3456
3456
3456
3456
3456

Step 2: Set the criteria — actual column numbers (one row)

=ArrayFormula(COLUMN(C3:F3))
3	4	5	6

Step 3: Final formula to get column totals (in C8)

=ArrayFormula(SUMIF(IF(ROW(C3:C7), COLUMN(C3:F7)), COLUMN(C3:F3), C3:F7))

This returns the sum of each column — like a pivot table’s total row.

Conclusion

We usually don’t think of SUMIF as a tool for matrix operations — but with a little creativity, it can handle sum of matrix rows or columns quite well.

If you’re already comfortable with SUMIF, this is a great way to reuse that knowledge in new ways. No need for complex matrix math — just a few helper functions and you’re good.

That’s all for now. Enjoy!

Additional Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

Pivot Table Formatting, Output & Special Behavior in Google Sheets

Pivot Tables in Google Sheets are powerful—but they can get tricky once you move...

Pivot Table Calculations & Advanced Metrics in Google Sheets

When it comes to built-in tools for data analysis and visualization in Google Sheets,...

Google Sheets Pivot Table Tutorial: Basics, Setup, and Date Grouping

The easiest way to summarize, analyze, and report data in Google Sheets is by...

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.