Sub topic 1
The IF Function for Simple Decisions in Excel
Prerequisites
You should know how to enter values and formulas, use cell references such as A1 and B2, and copy a formula down a column with the fill handle.
Quick refresher: formulas and cell references
An Excel formula begins with =. It can use values, operators, and cell references. A cell reference names a cell, so B2 means the value in column B, row 2. When a formula refers to a cell, Excel uses that cell's current value.
For example, if B2 contains 75, this formula calculates 10 more than that value:
=B2+10Asking a yes-or-no question with comparison operators
A logical test is a question whose result is either TRUE or FALSE. Comparison operators build these tests.
| Operator | Meaning | Example |
|---|---|---|
| `=` | equal to | `B2=60` |
| `<>` | not equal to | `B2<>60` |
| `>` | greater than | `B2>60` |
| `<` | less than | `B2<60` |
| `>=` | greater than or equal to | `B2>=60` |
| `<=` | less than or equal to | `B2<=60` |
If B2 contains 75, B2>=60 is TRUE. Excel can use that result to choose an outcome.
flowchart TD
A[Read the value in B2] --> B{Is B2 at least 60?}
B -->|TRUE| C[Return Pass]
B -->|FALSE| D[Return Fail]Writing your first IF formula
IF is a function that returns one result when a test is TRUE and another result when it is FALSE. Its structure is:
=IF(logical_test,value_if_true,value_if_false)For a score in B2, use:
=IF(B2>=60,"Pass","Fail")Excel tests B2>=60. It returns Pass for 60 or more and Fail for lower scores.
Returning text, numbers, and calculations
The two result arguments can be text, numbers, or calculations:
=IF(B2>=1000,B2*0.1,0)This returns a 10% bonus when sales reach 1,000. Otherwise, it returns zero. A formula can also return an empty string:
=IF(B2="","",B2*2)This leaves the result visually blank when B2 is empty.
Exercise
If C2 contains 58, what does =IF(C2>=60,"Pass","Fail") return?
Show answer
It returns "Fail" because 58 is less than 60.