Sub topic 2
Comparisons that return TRUE or FALSE
This chapter assumes you can write formulas with relative and absolute references and copy them across a row. It also assumes you know a basic forecast layout with periods in columns. Every flag and switch in this tutorial starts with a comparison, so it pays to know exactly what a comparison returns and where it goes wrong.
What a comparison is
A comparison is a formula that tests how two values relate and returns one of two answers: TRUE or FALSE. These two answers are called Boolean values (after the mathematician George Boole). A Boolean value is neither a number nor text. It is a third type of value that spreadsheets treat specially.
Here are two comparisons:
=F$5>=$C$10
=F30>0The first asks whether the period date in row 5 is on or after the start date in C10. The second asks whether pre-tax income in row 30 is positive. Each returns TRUE or FALSE for each period.
The six comparison operators
Excel has six comparison operators. Each sits between two values and returns a Boolean.
| Operator | Meaning | Example | Result when A1 = 5 |
|---|---|---|---|
| `=` | equal to | `=A1=5` | TRUE |
| `<>` | not equal to | `=A1<>5` | FALSE |
| `>` | greater than | `=A1>3` | TRUE |
| `<` | less than | `=A1<3` | FALSE |
| `>=` | greater than or equal to | `=A1>=5` | TRUE |
| `<=` | less than or equal to | `=A1<=4` | FALSE |
Two details trip people up:
- The first
=in=A1=5starts the formula. The second=is the comparison. The formula does not assign 5 to A1. - "Not equal" is written
<>, not!=. The other operators with two characters put the=last:>=and<=. Writing=>is an error.
Operands can be cells, constants, or formulas
Either side of a comparison can be a cell reference, a typed constant, or another formula:
=F30>0
=F30>$C$7
=F30>AVERAGE($F30:$J30)
=F$5=EOMONTH(F$5,0)The last example tests whether a date is a month-end date. It returns TRUE when the date in F5 equals the last day of its own month.
In a model, the value you compare against should usually be an input cell, not a typed constant. =F30>$C$7 lets you change the threshold in one place. =F30>50000 buries the threshold inside a formula where nobody will find it. The later chapters on timing flags and scenario switches rely on this habit.
Seeing the result
A cell holding a comparison displays TRUE or FALSE, centered by default. Booleans are aligned differently from numbers, which helps when you audit a row. If a row you expect to hold flags is right-aligned numbers or left-aligned text, check what the formula actually returns.
The following layout shows a timing test across a row. Row 5 holds period end dates and C10 holds a project start date:
=F$5>=$C$10Copied across, this formula gives:
| Row | F | G | H | I |
|---|---|---|---|---|
| Period end date (row 5) | 31-Jan-2027 | 28-Feb-2027 | 31-Mar-2027 | 30-Apr-2027 |
| Start date (C10) | 15-Mar-2027 | 15-Mar-2027 | 15-Mar-2027 | 15-Mar-2027 |
| `=F$5>=$C$10` | FALSE | FALSE | TRUE | TRUE |
The $ before C and 10 anchors the start date so every column compares against the same cell. The $ before 5 in F$5 lets the column move but keeps the row fixed.
TRUE and FALSE behave like 1 and 0, with limits
Models use 1/0 flags because numbers multiply and add easily. A Boolean is not a number, but Excel converts it when you do arithmetic on it:
=TRUE+0returns 1.=FALSE*100returns 0.=(F30>0)*F30returns F30 when it is positive and 0 otherwise.
The last formula is a flag built without IF. The comparison produces TRUE or FALSE, and multiplication turns it into 1 or 0. The chapter on combining flags develops this idea. For now, notice that the parentheses matter. Without them, Excel would apply the multiplication before the comparison.
Conversion happens only when you apply an arithmetic operator to the Boolean. Functions that take ranges handle Booleans differently:
SUM,AVERAGE,MIN, andMAXignore Boolean values stored in cells within a range.=SUM(F8:J8)over a row ofTRUE/FALSEreturns 0. The result is silent and plausible, which makes it a dangerous error.- A double negative converts the whole row:
=SUMPRODUCT(--(F8:J8))counts theTRUEvalues. The first-turns each Boolean into a negative number and the second turns it positive.
This is why many modelers convert comparisons to 1 and 0 explicitly, either with IF(test,1,0) or with --. A row of 1s and 0s can be summed, multiplied, and checked with a total.
What gets compared: numbers, dates, text, and blanks
A comparison is only as reliable as the types on each side. The common cases are below.
Numbers
Numbers compare by value. Negative numbers are smaller than positive ones, so =-5<2 is TRUE. Percentages are numbers: =C5>0.25 and =C5>25% are the same test.
Dates
Excel stores a date as a serial number (the count of days since a starting date), so date comparisons are number comparisons. =F$5>=$C$10 works because both cells hold numbers formatted as dates. Two traps follow from this:
- A date typed as text, such as a pasted
"2027-03-15"that Excel did not convert, is not a number. It will not compare correctly against real dates. Left-aligned "dates" are the usual sign. - A date with a time portion is not equal to the same date at midnight. Compare
INT(date)if times may be present.
Text
Text comparisons ignore case: ="Base"="BASE" is TRUE. They do respect extra spaces, so ="Base"="Base " is FALSE. A scenario name pasted with a trailing space will break a test silently.
Excel also orders text above numbers, so ="abc">5 is TRUE. The same applies to a number stored as text: ="10">5 is TRUE for that reason, even though 10 > 5 would have given the same answer by luck. ="10"<9 is FALSE, which is wrong from a numeric point of view. When a numeric comparison gives an odd answer, check whether either side is text. =ISNUMBER(A1) tells you.
Blank cells
A blank cell equals both 0 and the empty string:
=A1=0isTRUEwhen A1 is empty.=A1=""isTRUEwhen A1 is empty.
So a blank input can pass a test like =C3<=0 and trigger a flag. If a blank means "not provided", test it explicitly with =ISBLANK(C3) or =C3="" first.
Floating-point equality
Computers store most decimals in binary, which cannot represent values like 0.1 exactly. After many operations, two values that should match may differ in the 15th digit or beyond. An equality test such as =F40=F41 can then return FALSE when the values look identical on screen.
This matters in balance checks, where you test that assets equal liabilities plus equity. Compare a rounded difference with a tolerance instead of testing exact equality:
=ROUND(F50-F60,2)=0This returns TRUE when the two totals agree to the nearest cent. Use <, >, <=, and >= without worry, because small errors rarely change them. Equality is where the trouble appears.
Reading a comparison correctly: precedence
When a formula mixes arithmetic and comparison, Excel performs arithmetic first and comparison last. This gives sensible results:
=F20*1.1>F21Excel multiplies F20 by 1.1, then compares the result with F21. If you want the Boolean converted to a number first, put the comparison in parentheses, as in =(F20>F21)*1.1. When in doubt, add parentheses. They cost nothing and make the formula easier for the next reader.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Flag row total is 0 | `SUM` ignores `TRUE`/`FALSE` | Return 1/0 with `IF`, or use `SUMPRODUCT(--range)` |
| Date test is wrong for some columns | Header dates are text or contain times | Check with `ISNUMBER`; use real dates |
| Threshold test fires for a blank input | Blank equals 0 | Test `ISBLANK` or `=""` first |
| Name test fails although names look the same | Trailing space or different spelling | Use `TRIM`, or pick names from a drop-down list |
| Equality test returns `FALSE` on matching totals | Floating-point difference | Compare `ROUND(difference, n)` with 0 |
| Anchored reference moves when copied | Missing `$` | Anchor with `$C$10`, and mix with `F$5` for rows |
Comparisons in the larger model
A comparison on its own produces TRUE or FALSE, which is not yet a flag you can multiply by a line item. The next chapter wraps comparisons in IF to return exactly 1 or 0. After that, timing flags test a period date against start and end dates, and tax and debt formulas compare income and cash against zero. Each of those uses the operators and the type rules from this chapter.
Exercise
Cell F5 holds the period end date 30-Jun-2027. Cell C10 holds the start date 1-Jul-2027 and cell C11 holds the end date 31-Dec-2027. What do =F$5>=$C$10 and =F$5<=$C$11 return, and what does =(F$5>=$C$10)*(F$5<=$C$11) return?
Show answer
The first returns FALSE, because 30-Jun-2027 is earlier than 1-Jul-2027. The second returns TRUE, because 30-Jun-2027 is not later than 31-Dec-2027. The third multiplies FALSE (0) by TRUE (1) and returns 0, so the period is outside the active window.
Exercise
A row of cells G8:K8 contains the comparison results TRUE, TRUE, FALSE, TRUE, FALSE. What does =SUM(G8:K8) return, and what formula returns the number of TRUE values?
Show answer
=SUM(G8:K8) returns 0, because SUM ignores Boolean values stored in cells. =SUMPRODUCT(--(G8:K8)) returns 3. Converting the flags to 1/0 with IF in the first place would also let a plain SUM work.
Exercise
Cell C3 is empty. What does =C3<=0 return, and why can this be a problem for a model input?
Show answer
It returns TRUE, because a blank cell is treated as 0 in a numeric comparison. A flag that depends on this test would switch on when the user has not entered a value. Test =ISBLANK(C3) first, or require the input before the flag is evaluated.