Sub topic 1
Logical tests: the building block of every branch
Prerequisites
You should know how to enter and edit Google Sheets formulas, use cell references such as B2, and compare values with operators such as >=, <, and =. You should also know the basic IF function. This chapter uses those skills to prepare for IFS, SWITCH, and IFERROR.
A logical test is a formula that produces either TRUE or FALSE. Google Sheets uses that result to choose between branches, or paths, in a formula. For example, the test B2>=70 asks whether the value in B2 is at least 70.
=B2>=70If B2 contains 82, the result is TRUE. If B2 contains 64, the result is FALSE. A logical test does not have to compare numbers. It can compare text, dates, or the result of another function.
| Operator | Meaning | Example |
|---|---|---|
| `=` | equals | `A2="Paid"` |
| `<>` | does not equal | `A2<>"Canceled"` |
| `>` | greater than | `B2>100` |
| `>=` | greater than or equal to | `B2>=70` |
| `<` | less than | `B2<10` |
| `<=` | less than or equal to | `B2<=10` |
Combining logical tests
You can combine tests when one comparison is not enough. AND returns TRUE only when every test is TRUE. OR returns TRUE when at least one test is TRUE.
=AND(B2>=70,B2<90)
=OR(A2="Paid",A2="Pending")The first formula checks whether a score is from 70 through 89. The second formula accepts either Paid or Pending.
You can also place a logical test directly inside IF:
=IF(B2>=70,"Pass","Review")IF evaluates the test first. If the result is TRUE, it returns Pass. Otherwise, it returns Review. IFS extends this pattern to several conditions. Each condition still needs to produce TRUE or FALSE.
Boundaries and order
Pay close attention to boundaries. B2>70 excludes 70, while B2>=70 includes it. A small operator change can move a value into a different category.
When several ranges are tested, make the ranges complete and non-overlapping. For example, these tests classify scores correctly:
=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")IFS checks conditions from left to right and returns the value paired with the first TRUE condition. A score of 85 fails the first test, passes the second test, and returns B. The final TRUE condition is always true, so it provides a fallback for scores below 70.
Order matters because IFS stops at the first match. If you test B2>=70 before B2>=90, a score of 95 matches the 70 condition and receives the wrong result.
> callout note > Test the most specific or highest threshold first when your conditions overlap. Add a final TRUE condition when every input needs a defined result.
Choosing a logical structure
Use IF for one main test with two outcomes. Use IFS for ordered ranges or several different conditions. Use SWITCH when one expression must match exact values, such as status codes or department names. SWITCH(TRUE, ...) can test conditions in order, but IFS usually communicates range-based logic more directly.
Before writing a formula, ask:
- What value or expression am I testing?
- Are the possible conditions ordered?
- Can conditions overlap?
- What should happen when no condition matches?
- Should invalid input produce a visible error or a fallback message?
These questions prevent many later formula errors. They also make it easier to combine a decision function with IFERROR when an input may be missing or invalid.
Exercise
Write a logical test that returns TRUE when the value in C2 is either "Open" or "Pending".
Show answer
=OR(C2="Open",C2="Pending")