How to Use SUMIF Horizontally in Google Sheets

Published on

Most of the time, when we use SUMIF in Google Sheets, we think vertically — criteria in one column, numbers in another. But what if your data runs across rows instead of down columns?

For example, think about sales data by quarter. The quarters are in the header row, and the sales figures for each product sit across the row. That’s when you need to use SUMIF horizontally in Google Sheets.

In this guide, I’ll show you how to:

  • Sum values across columns based on one criteria.
  • Apply multiple criteria (like Q1 + Q2).
  • Spill results across multiple rows without dragging formulas.
  • Handle open ranges without clutter.

Sample Data

Here’s the dataset we’ll use. It shows sales for four products across Q1 to Q4 in both 2023 and 2024.

Quarterly sales data for Products A to D in 2023 and 2024, arranged across columns

Here, the header row (Q1–Q4 for each year) will be our criteria range, and each product row will be our sum range.

Example 1: SUMIF Horizontally with a Single Criterion

Let’s start simple: total sales for Product A in Q1 across 2023 and 2024.

=SUMIF($B$1:$I$1, "Q1*", B2:I2)

What’s happening here?

  • $B$1:$I$1 → header row (criteria range).
  • "Q1*" → criteria (matches Q1 in both years).
  • B2:I2 → sales data for Product A.

Result: 120 + 160 = 280

Now, how do we extend this to all products? Two options:

Option 1 — Drag down

Copy the formula down to apply it to Products B, C, and D.

Option 2 — Use BYROW for a spill

=BYROW(B2:I5, LAMBDA(r, SUMIF(B1:I1, "Q1*", r)))
Example of SUMIF horizontally in Google Sheets using BYROW to spill Q1 totals across multiple products

This way, you don’t have to copy formulas — the results spill automatically.

For open ranges with trailing blanks, use this version to skip unwanted zeros:

=BYROW(B2:I, LAMBDA(r, LET(total, SUMIF(B1:I1, "Q1*", r), IF(total=0,,total))))

Example 2: SUMIF Horizontally with Multiple Criteria

Now let’s say we want to total Q1 and Q2 together.

=SUMPRODUCT(SUMIF($B$1:$I$1, HSTACK("Q1*", "Q2*"), B2:I2))
How to apply SUMIF horizontally in Google Sheets with multiple criteria to sum Q1 and Q2 sales

Here’s the trick:

  • HSTACK → creates multiple criteria (Q1 and Q2).
  • SUMIF → returns separate sums for each.
  • SUMPRODUCT → adds them together in one step.

This works for one row (e.g., Product A).

Want to get results for all products? Here are two approaches:

Option 1 — Drag down

Just drag the formula down to cover Product B, C, and D.

Option 2 — Use BYROW for a spill

=BYROW(B2:I5, LAMBDA(r, SUMPRODUCT(SUMIF(B1:I1, HSTACK("Q1*", "Q2*"), r))))

This way, all product totals spill automatically without copying formulas.

If your range extends beyond data and may include empty cells, try this version:

=BYROW(B2:I, LAMBDA(r, LET(total, SUMPRODUCT(SUMIF(B1:I1, HSTACK("Q1*", "Q2*"), r)), IF(total=0,,total))))

Example 3: Yearly Totals

Sometimes, you don’t want just quarters — you want a whole year.

For 2023 totals (per product):

=SUMIF(B1:I1, "*2023", B2:I2)

For 2024 totals:

=SUMIF(B1:I1, "*2024", B2:I2)

Super clean!

Wrapping Up

Using SUMIF horizontally in Google Sheets unlocks a lot of flexibility when your data is structured across rows instead of columns.

Here’s what you learned today:

  • How to apply a single criterion (like Q1).
  • How to sum with multiple criteria (like Q1 + Q2).
  • How to use BYROW to spill results across multiple rows.
  • How to grab totals for an entire year.

Next time you’re tracking sales, budgets, or KPIs that run across a timeline, you’ll know exactly how to handle it.

Sample Google Sheet

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.