Sub topic 14
Getting OR logic
This chapter assumes you can already write SUMIFS, COUNTIFS, and AVERAGEIFS with several criteria pairs. It also assumes you know that criteria written as text, such as ">=10", are strings that Sheets parses. Here you will learn how to count, sum, and average rows that meet any of several conditions.
Why the functions do not do OR on their own
Every criteria pair you add to SUMIFS, COUNTIFS, or AVERAGEIFS narrows the result. A row must satisfy all pairs to be included, which is AND logic. The functions have no argument that means "either of these."
You can get OR by running the function once per alternative and combining the results. There are two situations, and they need different techniques:
- Same column, several values. For example, Region is West or East. The alternatives cannot both be true for one row, so you can add the results.
- Different columns. For example, Region is West or Units is at least 10. One row can satisfy both, so adding would count it twice. You must subtract the overlap.
The examples in this chapter use these rows in A2:E7, with columns Region, Product, Date, Units, and Revenue:
| Row | Region (A) | Product (B) | Date (C) | Units (D) | Revenue (E) |
|---|---|---|---|---|---|
| 2 | West | Widget | 2026-01-05 | 12 | 240 |
| 3 | East | Gadget | 2026-01-12 | 8 | 160 |
| 4 | North | Widget | 2026-02-03 | 15 | 300 |
| 5 | West | Gadget | 2026-02-10 | 5 | 100 |
| 6 | South | Widget | 2026-01-20 | 20 | 400 |
| 7 | East | Widget | 2026-03-01 | 10 | 200 |
Same column: an array constant
An array constant is a list of values written inside curly braces. When you give COUNTIFS an array constant as a criterion, it runs once per item and returns one result per item. Wrapping that in SUM adds the results:
=SUM(COUNTIFS(A2:A7, {"West","East"}))This returns 4. COUNTIFS counts 2 West rows and 2 East rows, and SUM adds them. Adding is correct here because no row has two regions.
SUMIFS works the same way. The sum range still comes first:
=SUM(SUMIFS(E2:E7, A2:A7, {"West","East"}))This returns 700, which is 240 + 100 + 160 + 200.
Adding more conditions
Other criteria pairs in the same formula apply to every alternative, so they act as AND filters on the whole OR group:
=SUM(COUNTIFS(A2:A7, {"West","East"}, D2:D7, ">=10"))This reads as "(West or East) and Units at least 10." It returns 2, for rows 2 and 7. The array constant is evaluated once per item, and each evaluation includes the D2:D7 condition.
Alternatives stored in cells
Hard-coded lists are awkward to change. If the alternatives sit in G2:G3, pass that range as the criterion. Wrapping the formula in ARRAYFORMULA makes Sheets evaluate the criteria range item by item:
=ARRAYFORMULA(SUM(COUNTIFS($A$2:$A$7, G2:G3)))You can then add or remove regions by editing the cells, as long as the range G2:G3 covers them. Add a spare blank cell to the range and the blank criterion will not match any text region, but it can match other rows in different data. Keep the criteria range exactly as long as your list.
Operators inside an array constant
Each item can include operators, so one formula can cover several ranges of one column. This counts rows where Units is below 6 or above 14:
=SUM(COUNTIFS(D2:D7, {"<6",">14"}))It returns 3, for rows 5, 4, and 6. This is safe to add because no number is both below 6 and above 14. If the ranges overlapped, such as {"<10","<20"}, rows below 10 would be counted twice.
Locale and separators
Inside array constants, a comma separates items across columns (a row array) and a semicolon separates items down rows (a column array). Some locales that use a decimal comma swap these characters. If Sheets rejects a constant, check File > Settings for your locale and try the other separator.
Different columns: add, then subtract the overlap
Suppose you want rows where Region is West or Units is at least 10. Adding the two counts double-counts any row that meets both conditions. The fix is inclusion-exclusion: add both counts, then subtract the rows that meet both.
=COUNTIFS(A2:A7, "West") + COUNTIFS(D2:D7, ">=10") - COUNTIFS(A2:A7, "West", D2:D7, ">=10")Work through the numbers:
- West rows: 2 (rows 2 and 5).
- Units at least 10: 4 (rows 2, 4, 6, and 7).
- Both: 1 (row 2).
- Result: 2 + 4 − 1 = 5.
The same pattern works for SUMIFS. Replace each COUNTIFS with a SUMIFS that has the same sum range:
=SUMIFS(E2:E7, A2:A7, "West") + SUMIFS(E2:E7, D2:D7, ">=10") - SUMIFS(E2:E7, A2:A7, "West", D2:D7, ">=10")This returns 240 + 100 + 240 + 300 + 400 + 200 − 240 = 1240 − 0... more simply: the union rows are 2, 4, 5, 6, and 7, and their revenue is 240 + 300 + 100 + 400 + 200 = 1240.
For three or more overlapping conditions, inclusion-exclusion needs pairwise and triple overlaps, and the formula grows quickly. At that point a helper column or a different tool is easier (see the last section).
OR with AVERAGEIFS
You cannot average several AVERAGEIFS results. The average of two averages is wrong unless both groups have the same number of rows. Instead, compute the total and the count with OR logic, then divide:
=IFERROR(SUM(SUMIFS(E2:E7, A2:A7, {"West","East"})) / SUM(COUNTIFS(A2:A7, {"West","East"})), "No matches")With the sample data this is 700 / 4 = 175. IFERROR catches the #DIV/0! error that appears when the count is 0, in the same way as for a single AVERAGEIFS.
Compare this with a naive version, (AVERAGEIFS(E2:E7, A2:A7, "West") + AVERAGEIFS(E2:E7, A2:A7, "East")) / 2. It returns (170 + 180) / 2 = 175 here only because both regions have two rows. With unequal row counts it gives a different, wrong answer.
Common errors
- Using two array constants in one formula. Sheets pairs the items by position instead of trying every combination. For OR across two columns, use the add-and-subtract pattern instead.
- Forgetting SUM.
=COUNTIFS(A2:A7, {"West","East"})returns an array. In a single cell the display shows only the first result (2 for West), or spills into neighbouring cells. Always wrap it in SUM when you want one total. - Using a range criterion without ARRAYFORMULA. A criterion range such as
G2:G3may evaluate only its first cell. Wrap the formula in ARRAYFORMULA when the alternatives live in cells. - Overlapping alternatives. Items such as
{"<10","<20"}count the same rows twice. Make the items mutually exclusive. - Mismatched range sizes. Each added SUMIFS or COUNTIFS in a subtraction formula still needs equal-length ranges. A mismatch in one term returns an error for the whole formula.
When OR gets unwieldy
Several OR conditions across different columns turn a short formula into a long one. Other options are:
- FILTER with
+for OR and*for AND, then wrap in SUM or COUNTA. - QUERY, which supports
ordirectly in itswhereclause. - A helper column holding
=OR(A2="West", D2>=10), which you then count withCOUNTIFS(F2:F7, TRUE).
Chapter 16 compares these tools in more detail. For one or two OR alternatives, the formulas in this chapter are short and reliable.
Exercise
Using the sample data in A2:E7, write a formula that returns the total Revenue for rows where Region is South or North and Units is greater than 14. What does it return?
Show answer
=SUM(SUMIFS(E2:E7, A2:A7, {"South","North"}, D2:D7, ">14")). The array constant produces one SUMIFS per region, each with the Units condition applied. North (row 4) has 15 units and revenue 300, and South (row 6) has 20 units and revenue 400. The formula returns 700. Adding is safe because a row cannot be in both regions.
Exercise
A colleague writes =AVERAGEIFS(E2:E7, A2:A7, "West") + AVERAGEIFS(E2:E7, A2:A7, "East") to get the average Revenue for West or East, and then divides by 2. Under what condition is this wrong, and what formula fixes it?
Show answer
It is wrong whenever West and East have different numbers of rows, because it gives each region's average equal weight regardless of row count. The fix is to divide the OR-combined total by the OR-combined count: =IFERROR(SUM(SUMIFS(E2:E7, A2:A7, {"West","East"})) / SUM(COUNTIFS(A2:A7, {"West","East"})), "No matches").