Sub topic 6
Comparison operators in criteria: `>`, `<`, `>=`, `<=`, `<>`, `=`
Assume you can enter Google Sheets formulas and use ranges such as A2:A100. You should also know the difference between text, numbers, and dates. This chapter shows how comparison operators control which rows COUNTIFS, SUMIFS, and AVERAGEIFS include.
A comparison operator is a symbol that tests a cell's value against a criterion. In an IFS function, write the operator and value together as a criterion string.
| Operator | Meaning | Example criterion |
|---|---|---|
| `>` | greater than | `">100"` |
| `<` | less than | `"<100"` |
| `>=` | greater than or equal to | `">=100"` |
| `<=` | less than or equal to | `"<=100"` |
| `<>` | not equal to | `"<>West"` |
| `=` | equal to | `"=West"` |
Apply a comparison to numbers
Suppose column D contains Units and column E contains Revenue. To count rows with at least 10 units, use:
=COUNTIFS(D2:D100, ">=10")The range is D2:D100. The criterion is ">=10". The quotation marks are required because the criterion contains an operator.
To sum revenue from rows with more than 10 units, use:
=SUMIFS(E2:E100, D2:D100, ">10")SUMIFS takes the range to sum first. It then takes a criteria range and its matching criterion.
To calculate the average revenue for rows with 10 or fewer units, use:
=AVERAGEIFS(E2:E100, D2:D100, "<=10")AVERAGEIFS also takes its result range first. The function averages only the values whose units meet the condition.
Compare with text
The same operators can compare text. To count rows where Region is not West, use:
=COUNTIFS(A2:A100, "<>West")To count exactly West, you can write either of these:
=COUNTIFS(A2:A100, "West")=COUNTIFS(A2:A100, "=West")The first form is shorter and is usually clearer. Text comparisons are not case-sensitive, so west matches West.
Use several comparisons together
Each criteria pair must be true for a row to qualify. This is AND logic:
=SUMIFS(E2:E100, A2:A100, "West", D2:D100, ">=10")This sums revenue only when the region is West and units are at least 10.
Avoid boundary and type errors
A number stored as text may not behave like a number in a comparison. Dates must also be real date values, not text that only looks like a date. Check the cell format and test a small range if results seem wrong.
Also keep every range the same size. In this formula, all ranges cover rows 2 through 100:
=AVERAGEIFS(E2:E100, A2:A100, "West", D2:D100, ">=10")If one range ends at row 99 or starts at row 3, the formula can return an error or misleading results.
Exercise
Which formula counts rows where Units is greater than or equal to 25 and Region is not East?
Show answer
=COUNTIFS(D2:D100, ">=25", A2:A100, "<>East")