Sub topic 15
OR Logic: Several Values for One Field
This chapter assumes you can write a basic SUMIFS or COUNTIFS formula, know the difference between relative and absolute references, and have used SUM on a range. The sample data is the sales layout used throughout this tutorial: Date in column A, Region in B, Product in C, Amount in D, and Notes in E, with data in rows 2 to 100.
Why the *IFS functions do not do OR on one field
Every criteria pair in SUMIFS, COUNTIFS, and AVERAGEIFS is combined with AND. A row is counted only if all conditions are true. That is the right behavior for "West and Laptop". It gives the wrong answer for "West or East".
A single cell in the Region column holds one value. It cannot be both West and East. So this formula returns 0, not the combined total:
=SUMIFS(D2:D100, B2:B100, "West", B2:B100, "East")No row can satisfy both pairs at once. To get OR on one field, you run the condition once for each value and combine the results. There are two common ways to do this.
Method 1: add separate formulas
The most readable approach is to write one SUMIFS per value and add them.
=SUMIFS(D2:D100, B2:B100, "West") + SUMIFS(D2:D100, B2:B100, "East")Each SUMIFS applies AND logic to its own conditions. The + then provides the OR. This works because the two sets of rows do not overlap: a row has one region, so no row is counted twice.
This method works in every version of Excel that has SUMIFS. It is easy to audit, and you can add other conditions to each part. For example, to total West or East laptop sales:
=SUMIFS(D2:D100, B2:B100, "West", C2:C100, "Laptop") + SUMIFS(D2:D100, B2:B100, "East", C2:C100, "Laptop")The cost is length. With five regions, the formula has five terms, and any change to a shared condition must be made in every term.
Method 2: an array constant inside SUM
An array constant is a list of values written inside curly braces, such as {"West","East"}. If you pass an array constant as a criteria argument, SUMIFS evaluates once per item and returns an array of results. SUM then adds them.
=SUM(SUMIFS(D2:D100, B2:B100, {"West","East"}))For the sample data, SUMIFS returns two numbers, one for West and one for East. SUM adds them into one total.
The same pattern works for COUNTIFS:
=SUM(COUNTIFS(B2:B100, {"West","East"}, C2:C100, "Laptop"))This counts laptop rows in West or East. The other criteria pair applies to every item in the array.
Here is how the two methods compare.
| Aspect | Add separate SUMIFS | Array constant inside SUM |
|---|---|---|
| Formula length | Grows with each value | Nearly constant |
| Readability | Each term is plain | Needs knowledge of array results |
| Adding a value | Add a whole new term | Add one item to the braces |
| Values from cells | Reference each cell in its own term | Needs a range instead of a constant |
Using values from cells instead of constants
An array constant is typed into the formula, so changing the list means editing the formula. If the values live in cells, you can pass a range as the criteria argument. Suppose G1:G2 contain West and East:
=SUM(SUMIFS(D2:D100, B2:B100, G1:G2))SUMIFS evaluates once for each cell in G1:G2. In current versions of Excel (Microsoft 365 and Excel 2021 and later), this works as shown. In older versions it may need to be entered as an array formula with Ctrl+Shift+Enter, or you can use SUMPRODUCT in place of SUM, which handles arrays without special entry:
=SUMPRODUCT(SUMIFS(D2:D100, B2:B100, G1:G2))Because the list is in cells, a user can change the regions without touching the formula.
OR across different fields
The methods above are for several values of one field. If the OR is across different fields, such as "Region is West or Product is Laptop", the problem changes. Adding two SUMIFS results would count West laptop rows twice, because those rows satisfy both conditions.
The fix is inclusion-exclusion. Add the two totals, then subtract the overlap:
=SUMIFS(D2:D100, B2:B100, "West") + SUMIFS(D2:D100, C2:C100, "Laptop") - SUMIFS(D2:D100, B2:B100, "West", C2:C100, "Laptop")This is the one case where the plain "add the pieces" rule needs care. Always ask whether a single row can match more than one of the pieces.
Edge cases and common errors
- Overlapping values. If your list contains values that can match the same row, the row is counted more than once. This happens with wildcards.
{"W*","West"}matches every West row twice, so the total is doubled for those rows. Keep list items mutually exclusive. - Forgetting SUM.
=SUMIFS(D2:D100, B2:B100, {"West","East"})entered alone returns an array of two values. In current Excel the results spill into neighboring cells. In older Excel you see only the first value, which is the West total, and no error. Always wrap the formula in SUM. - AVERAGEIFS does not combine this way. Averaging with the same pattern gives an average of the two averages, which is wrong when West and East have different row counts. To average West or East rows, divide the combined sum by the combined count:
=SUM(SUMIFS(D2:D100, B2:B100, {"West","East"})) / SUM(COUNTIFS(B2:B100, {"West","East"}))- Zero matches. If neither value appears, the count is 0 and the division above returns #DIV/0!. Wrap it in IFERROR as shown in the AVERAGEIFS chapter.
- Mixing array constants and cell ranges in the same list. You cannot write
{"West", G1}. Array constants hold only literal values, not cell references.
Choosing a method
Use the addition method when you have two or three values, when each term has different extra conditions, or when readers who are new to arrays must maintain the file. Use the array constant when the list is longer but fixed. Use a range of criteria cells when the list changes often. If you have many OR conditions across several fields, a PivotTable with a filter or a SUMPRODUCT formula, covered in the last chapter, is usually clearer.
Exercise
Using the sample data, write one formula that returns the number of rows where Region is North or East and the Notes cell is blank. Then explain why =COUNTIFS(B2:B100, "North", B2:B100, "East") returns 0.
Show answer
Use =SUM(COUNTIFS(B2:B100, {"North","East"}, E2:E100, "")). The array constant runs the count once for North and once for East, the "" criterion matches blank notes in each run, and SUM adds the two counts. The formula with two pairs on column B returns 0 because the pairs are joined with AND, and no row has a Region that is both North and East.
Exercise
A colleague writes =SUM(SUMIFS(D2:D100, B2:B100, {"West","W*"})) to total West sales. The result is larger than the true West total. Why, and how do you fix it?
Show answer
The criteria "West" and "W" both match every West row, so each West amount is added twice. Remove one item: use a single criterion, either "West" or "W", or make the list values mutually exclusive.