Sub topic 14
Getting OR Logic
Assume you know how to enter formulas, use ranges such as A2:A100, and write basic COUNTIFS and SUMIFS formulas. This chapter shows how to match rows that satisfy one condition or another.
COUNTIFS and SUMIFS combine separate criteria with AND logic by default. For example, this counts rows whose Region is both "West" and whose Product is both "Widget":
=COUNTIFS(A2:A100, "West", B2:B100, "Widget")A row cannot have two different values in the same Region cell at once. To express “West or East,” calculate one result for each value and add the results.
OR with COUNTIFS
Google Sheets can pass an array constant, such as {"West","East"}, to COUNTIFS. The function returns one count for each item. SUM then combines those counts:
=SUM(COUNTIFS(A2:A100, {"West","East"}))The formula means:
- Count rows where Region is
"West". - Count rows where Region is
"East". - Add the two counts.
The same pattern works with another criterion:
=SUM(COUNTIFS(A2:A100, {"West","East"}, D2:D100, ">=10"))This counts rows from either region that also have at least 10 units. The units condition remains AND logic because it applies to both region alternatives.
OR with SUMIFS
For totals, wrap SUMIFS in SUM:
=SUM(SUMIFS(E2:E100, A2:A100, {"West","East"}))Here, E2:E100 is the range to add. Google Sheets calculates a West total and an East total, then adds them.
| Goal | Formula pattern |
|---|---|
| Count West or East rows | `=SUM(COUNTIFS(A2:A100, {"West","East"}))` |
| Sum Revenue for West or East | `=SUM(SUMIFS(E2:E100, A2:A100, {"West","East"}))` |
This method is safe when each row can match only one alternative, as with a single Region cell. If alternatives can overlap, adding separate results can count the same row twice.
OR across different columns
Suppose you need rows where Region is West or Product is Widget. Separate COUNTIFS formulas can overlap:
=COUNTIFS(A2:A100, "West") + COUNTIFS(B2:B100, "Widget")A row that is both West and Widget is counted twice. For unique-row logic, use FILTER with addition as the OR test:
=COUNTA(FILTER(A2:A100, (A2:A100="West") + (B2:B100="Widget")))In this expression, each comparison produces TRUE or FALSE values. Addition treats either TRUE condition as a match. FILTER returns the matching rows, and COUNTA counts them.
Exercise
Write a formula that sums Revenue in E2:E100 for rows whose Region is either North or South.
Show answer
=SUM(SUMIFS(E2:E100, A2:A100, {"North","South"}))