Sub topic 2
Comparing values: =, <>, >, <, >=, <=
Assume you can enter formulas and use cell references such as A1 and B2. You should also know basic arithmetic operators such as + and *. This chapter focuses on comparison operators, which let Google Sheets compare two values.
A comparison operator is a symbol that asks how two values relate. The result is a Boolean value: TRUE or FALSE. You can use that result by itself, or use it as the test in an IF formula.
The six comparison operators
| Operator | Meaning | Example | Result |
|---|---|---|---|
| `=` | Equal to | `=B2=50` | `TRUE` if B2 is 50 |
| `<>` | Not equal to | `=B2<>50` | `TRUE` if B2 is not 50 |
| `>` | Greater than | `=B2>50` | `TRUE` if B2 is above 50 |
| `<` | Less than | `=B2<50` | `TRUE` if B2 is below 50 |
| `>=` | Greater than or equal to | `=B2>=50` | `TRUE` if B2 is at least 50 |
| `<=` | Less than or equal to | `=B2<=50` | `TRUE` if B2 is at most 50 |
For example, if B2 contains 72, this formula returns TRUE:
=B2>=50The value 72 is greater than 50, so the comparison is true. If B2 contains 49, the same formula returns FALSE.
Using comparisons inside IF
An IF formula uses a comparison as its first argument. The formula then returns one result when the comparison is true and another when it is false.
=IF(B2>=50, "Pass", "Fail")If B2 is 50 or higher, the result is Pass. If it is lower than 50, the result is Fail.
The choice between > and >= matters at the boundary. Use B2>50 when exactly 50 should fail. Use B2>=50 when exactly 50 should pass.
The not-equal operator is useful when a value must differ from a specific value:
=IF(A2<>"Cancelled", "Process", "Skip")This returns Process for every status except Cancelled.
Comparing text
Put text inside double quotation marks. For example:
=IF(A2="Paid", "Done", "Follow up")This compares the contents of A2 with the text Paid. In Google Sheets, text comparison with = is not case-sensitive, so paid, Paid, and PAID match.
Text comparisons still depend on the actual characters. A trailing space can cause an unexpected result. For example, Paid has an extra space and may not match Paid. If imported data contains extra spaces, clean it with TRIM:
=IF(TRIM(A2)="Paid", "Done", "Follow up")Understanding the comparison flow
Common boundary errors
A formula can be syntactically correct but logically wrong. Check these cases:
>excludes the boundary value.>=includes the boundary value.<excludes the boundary value.<=includes the boundary value.=tests equality. It does not mean “assign this value” in a spreadsheet formula.<>means “different from,” not “less than.”
When comparing dates, use real date values rather than text that only looks like a date. A date comparison works only when Sheets recognizes both values as dates.
> callout note > Test the boundary value directly. If the passing score is 50, try a row with 49, one with 50, and one with 51. This reveals whether your operator matches the rule.
Practice
Suppose column A contains a payment status and column B contains an amount. Write a formula that returns Review when the amount is less than or equal to 0, and returns OK otherwise.
Exercise
What formula returns Review for a value in B2 that is 0 or below, and OK for a positive value?
Show answer
=IF(B2<=0, "Review", "OK")