Lesson 3 of 8 · see all lessons
  1. Formulas from zero

    1. 1. Excel basics: cells, ranges and your first SUM formula
    2. 2. Relative vs absolute references in Excel ($A$1)
    3. 3. How to use the IF function in Excel (and nested IF)
  2. Answer questions with conditions and lookups

    1. 4. SUMIFS and COUNTIFS in Excel: add and count with conditions
    2. 5. How to use XLOOKUP in Excel (and VLOOKUP when you have to)
  3. Organize and summarize the month

    1. 6. How to sort, filter and make a table in Excel
    2. 7. How to make a pivot table in Excel
    3. 8. Excel practice: build a monthly sales report

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:

  1. logical_test: the question, such as H2>=30 (is the Total 30 or more?)
  2. value_if_true: the answer when the test is true
  3. 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.

[10]

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.

  1. ,"Small"
  2. =IF(
  3. )
  4. ,"Big"
  5. H2>=30

excel
K1: Size
K2: =IF(H2>=30,"Big","Small") (fill down to K31)
Expected: K2 Small (28.00 is under 30). K8 Big (42.00). Six rows in all say Big.

Predict, then reveal

Change one thing: make the test H2>=40. How many rows say Big now?

[10]

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.

excel
K2: =IF(H2>=30,"Big",IF(H2>=15,"Medium","Small")) (fill down)
Expected: K2 Medium (28.00), K7 Small (8.00), K8 Big (42.00). Count: 6 Big, 16 Medium, 8 Small.

Step through

How Excel reads the nested IF, row by row

  1. >=30 Big0test
  2. >=15 Medium1
  3. else Small2

Row 2, Total 28.00. Is 28 >= 30? FALSE, so move to the inner IF.

Step 1 of 6

[10]

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.

[11][29]

excel
K2: =IFS(H2>=30,"Big",H2>=15,"Medium",TRUE,"Small")
Expected: exactly the same bands as the nested IF. Without the TRUE pair, a row that fails every test shows #N/A.

[11]

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.

[9][12]

excel
L1: Weekend
L2: =IF(OR(B2="Sat",B2="Sun"),"Weekend","Weekday") (fill down)
Expected: L2 Weekday (a Monday), L8 Weekend (a Saturday). Ten rows say Weekend. Lesson 4 uses this column.

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.

[9]

FlashcardsIndex cardsFlashcards ⚡

Card 1 of 16

Worth keeping

  1. IF has three parts: a test, the answer if true, the answer if false.
  2. Nest IFs (or use IFS) for more than two answers, and test the biggest threshold first.
  3. Check the boundary value: >= includes it, > doesn't.
  4. 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.

  1. [9]Microsoft Support: AND function
  2. [10]Microsoft Support: IF function
  3. [11]Microsoft Support: IFS function
  4. [12]Microsoft Support: OR function
  5. [29]Google Docs Editors Help: IFS function