Lesson 3 of 8 · see all lessons
Formulas from zero
Answer questions with conditions and lookups
Organize and summarize the month
11 min
How to use the IF function in Excel (and nested IF)
IF checks a condition and returns one value if it's true and another if it's false. Learn IF, nested IF, IFS, AND and OR on real sales rows.
By the end of this lesson you can
- Write an IF with a test, a true answer and a false answer
- Nest IFs (or use IFS) to sort rows into three bands
- Put the tests in the right order and handle the boundary value
- Combine conditions with OR and AND
From earlier lessons · 1 of 2
H2 holds =E2*F2. You fill it down to H31. What is in H9?
Pick one answer.
From earlier lessons · 2 of 2
Which share formula can you fill down column I without errors?
Pick one answer.
The manager scans the Total column and says: flag the big ones. Doing it by eye means 30 decisions, and you'll redo all of them when a number changes. A formula can decide once for every row.
Take a guess
The manager calls an order line Big if its Total is 30.00 or more. Of the 30 rows, how many are Big?
No pressure. Guess now, and the lesson will show you if you were right.
IF: one test, two answers
IF asks a yes-or-no question and gives one of two answers. It has three parts, separated by commas:
- logical_test: the question, such as H2>=30 (is the Total 30 or more?)
- value_if_true: the answer when the test is true
- value_if_false: the answer when it's false
Text answers go inside double quotes. Numbers don't. The comparison signs are =, <>, >, <, >= and <=. The sign <> means not equal to.
Put in order
Put the parts of the Big/Small formula in order.
Drag, or focus an item and press Space, move with the arrow keys, then Space to drop.
- ,"Small"
- =IF(
- )
- ,"Big"
- H2>=30
K1: SizeK2: =IF(H2>=30,"Big","Small") (fill down to K31)
Predict, then reveal
Change one thing: make the test H2>=40. How many rows say Big now?
Three bands: nested IF
The manager wants three bands: Big at 30 or more, Medium at 15 or more, and Small for the rest. One IF gives two answers. For a third, put a second IF in the false slot of the first. That's a nested IF. Excel stops at the first test that is true.
K2: =IF(H2>=30,"Big",IF(H2>=15,"Medium","Small")) (fill down)
Step through
How Excel reads the nested IF, row by row
- >=30 Big0test
- >=15 Medium1
- else Small2
Row 2, Total 28.00. Is 28 >= 30? FALSE, so move to the inner IF.
A colleague writes =IF(H2>=15,"Medium",IF(H2>=30,"Big","Small")). What does row 8 (Total 42.00) show?
Pick one answer.
Rows 4 and 18 each have a Total of exactly 15.00. You change the inner test to H2>15. What do those two rows show now?
Pick one answer.
IFS does the same job with less nesting. You list test, answer, test, answer. Use TRUE as the last test to catch everything else. IFS needs Excel 2019 or later or Microsoft 365, and Google Sheets has it too.
K2: =IFS(H2>=30,"Big",H2>=15,"Medium",TRUE,"Small")
Two conditions: OR and AND
Next question: which rows were on a weekend? The Day column says Sat or Sun. OR returns TRUE if any of its tests is true. AND returns TRUE only if all of them are. Put either one in IF's test slot.
L1: WeekendL2: =IF(OR(B2="Sat",B2="Sun"),"Weekend","Weekday") (fill down)
The café pays a bonus when Ana sells a Big line. =IF(AND(G2="Ana",H2>=30),"Bonus","") is filled down. How many rows say Bonus?
Pick one answer.
FlashcardsIndex cardsFlashcards ⚡
Card 1 of 16Worth keeping
- IF has three parts: a test, the answer if true, the answer if false.
- Nest IFs (or use IFS) for more than two answers, and test the biggest threshold first.
- Check the boundary value: >= includes it, > doesn't.
- OR needs any test true; AND needs every test true. Text always goes in quotes.
Every row now carries a Size and a Weekend label. The manager's real question is money: how much did weekends bring in? Ten rows out of thirty sounds like a third. It isn't even close, and one formula that adds only matching rows will show why.
Embed this practice on your site
Free for classrooms, blogs and study groups. Paste this into any page that accepts HTML.
Report a copyright problem with this lesson
Sources for this lesson (5)
Each fact in the lesson is marked with the number of the page it comes from.