Sub topic 7
Using >, <, >=, <=, and <> in criteria
This chapter assumes you can enter and copy formulas, understand relative and absolute references, and know the basic SUMIFS, COUNTIFS, and AVERAGEIFS argument order. The examples use the sample sales layout, with headers in row 1 and data in rows 2 to 100.
How operators work in criteria
A criterion that is just a value, such as "West", tests for equality. To test for "greater than", "not equal", and similar conditions, you put the operator at the start of the criterion text. The operator and the value form one string.
| Operator | Meaning | Example criterion |
|---|---|---|
| `=` | Equal to (the default) | `"=West"` |
| `>` | Greater than | `">500"` |
| `<` | Less than | `"<500"` |
| `>=` | Greater than or equal to | `">=500"` |
| `<=` | Less than or equal to | `"<=500"` |
| `<>` | Not equal to | `"<>West"` |
The quotation marks are required. Writing >500 without them is a formula syntax error.
=SUMIFS(D2:D100, D2:D100, ">500")This adds every Amount over 500. The sum range and the criteria range are the same column here. That is allowed and common.
Reading the criterion from a cell
Hard-coded thresholds are hard to change. Put the threshold in a cell, such as G1, and join it to the operator with &.
=SUMIFS(D2:D100, B2:B100, "West", D2:D100, ">=" & G1)The operator stays in quotation marks. The cell reference stays outside them. Excel joins the two into a string like ">=500" before it evaluates the criterion. This formula totals West rows whose Amount is at least the value in G1.
Not equal to
<> excludes a value. This counts every row that is not in the West region:
=COUNTIFS(B2:B100, "<>West")Two details matter. First, <> matches blank cells too, because a blank is not "West". Second, a criterion that is only "<>" means "not empty". The blank-criteria chapter covers that case.
Comparing text
Operators also work on text, using alphabetical order. "<M" matches text that sorts before "M". Comparisons ignore letter case. Use this sparingly, because it is easy to misread.
Common mistakes
- Missing quotation marks.
>500fails, and">500"works. - Missing
&.">="G1is a syntax error. Join the pieces with">=" & G1. - Numbers stored as text. A criterion such as
">500"only compares against real numbers. If the Amount column holds text that looks like numbers, those cells are skipped. Check that the cells are right-aligned by default and that=ISNUMBER(D2)returns TRUE. - Using
!=for not equal. Excel uses<>.
Exercise
Column D holds amounts and cell G1 holds 300. Write a COUNTIFS formula that counts the rows in D2:D100 with an Amount strictly less than G1 and a Region (column B) that is not "East".
Show answer
=COUNTIFS(D2:D100, "<" & G1, B2:B100, "<>East")
Exercise
A formula contains the criterion ">=G1" and always returns 0, even though several amounts are above the value in G1. What is wrong, and how do you fix it?
Show answer
The criterion is a plain string, so Excel compares against the text "G1" instead of the cell's value. Join the operator and the reference with an ampersand: ">=" & G1.