Why IF is the first logical function to learn
Most spreadsheets eventually need to make a decision. Is this department over budget? Did this employee pass the test? Is this invoice late? Should this customer get a discount? If you answer those questions by reading each row and typing a label by hand, the work is slow, error-prone and has to be repeated every time a number changes. The IF function lets Excel make the decision for you, consistently, for every row, and update the answer the moment the data changes.
This lesson is for anyone who has seen IF in someone else’s workbook and wants to write it with confidence: office staff, team leads who own a budget, finance and HR assistants, students and analysts. In the free lab above you work for Brightline Outdoor Co., a fictional outdoor-gear retailer. You flag the departments that went over budget, calculate how much they overspent, grade a staff safety test against a pass mark and chart budget against actual. This article covers the same tasks in depth, with the reasoning, the exact formulas and the traps that catch beginners.
By the end you will understand not only how to type an IF formula, but how to think about the test inside it. That skill carries straight over to AND, OR, IFS, SWITCH and every other logical function in the rest of the course.
The core concept: one question, two possible answers
IF takes three arguments: =IF(logical_test, value_if_true, value_if_false). The first argument is a question that can only be answered TRUE or FALSE. The second argument is what Excel should return when the answer is TRUE. The third is what it should return when the answer is FALSE. That is the whole function. Everything else is about writing a good question and choosing useful answers.
The question is almost always a comparison between two values, built with one of six operators. Reading the operators aloud is the fastest way to avoid mistakes, because the plain-English version of a business rule usually tells you which one to use. "At least 70 points" is >=70. "More than the budget" is >B2. "Not equal to zero" is <>0.
| Operator | Read it as | Example | TRUE when |
|---|---|---|---|
= | equals | C2=B2 | actual is exactly the budget |
<> | is not equal to | A2<>"HR" | the department is anything but HR |
> | greater than | C2>B2 | actual is above budget |
< | less than | C2<B2 | actual is below budget |
>= | at least | B14>=$B$11 | score reaches the pass mark |
<= | at most | C2<=B2 | actual does not exceed budget |
The answers can be text, numbers, cell references or entire calculations. Text must sit in double quotes: "Over". Numbers and references must not: 0 or C2-B2. If you forget the quotes around text, Excel thinks Over is the name of a range and returns the #NAME? error. If you put quotes around a number, you get text that looks like a number but no longer adds up in totals.
=IF(C2>B2,"Over") returns the word FALSE for departments within budget, which looks untidy in a report. Always give IF both answers, even if one of them is an empty string "".Worked example: Brightline Outdoor’s department budgets
Brightline’s finance team has the annual budget and the actual spending for eight departments. The table below shows the data from the lab with the two columns you add: a status label and the overspend in currency. All amounts are fictional.
| Department | Budget (B) | Actual (C) | Status (D) | Overspend (E) |
|---|---|---|---|---|
| Marketing | 48,000 | 51,250 | Over | 3,250 |
| Sales | 62,000 | 58,900 | Within | 0 |
| Warehouse | 35,500 | 35,500 | Within | 0 |
| IT | 28,000 | 31,420 | Over | 3,420 |
| HR | 18,500 | 17,960 | Within | 0 |
| Customer care | 22,000 | 23,150 | Over | 1,150 |
| Finance | 15,000 | 14,280 | Within | 0 |
| E-commerce | 40,000 | 44,800 | Over | 4,800 |
The status formula in D2 is =IF(C2>B2,"Over","Within"). Copy it down to D9 and Excel asks the same question for every department. Marketing spent 51,250 against a budget of 48,000, so the test is TRUE and the cell shows Over. Sales spent 58,900 against 62,000, so the test is FALSE and the cell shows Within.
The Warehouse row is the interesting edge case: budget and actual are both 35,500. Is spending exactly the budget "over"? Under the rule C4>B4 it is not, because 35,500 is not greater than 35,500, so the answer is Within. That matches the usual business meaning: a department that spends its budget to the cent has not overspent. If your organisation defines it differently, the fix is a single character, >=. The point is that you choose deliberately, rather than letting the operator choose for you.
The overspend column shows that IF can return a calculation, not just a label. =IF(C2>B2,C2-B2,0) returns the difference when the department is over and zero when it is not. Without the IF, a simple =C6-B6 would show −540 for HR, which would then reduce the total overspend of the company and make the report misleading. For this particular pattern there is also a shorter formula, =MAX(0,C2-B2), which returns the larger of zero and the difference. Both are correct. IF is easier to read for most people; MAX is neater once you know the trick.
| Cell | Formula | Result for that row |
|---|---|---|
| D2 | =IF(C2>B2,"Over","Within") | Over (Marketing spent 51,250 of 48,000) |
| D4 | =IF(C4>B4,"Over","Within") | Within (Warehouse is exactly on budget) |
| E5 | =IF(C5>B5,C5-B5,0) | 3,420 (IT) |
| E6 | =IF(C6>B6,C6-B6,0) | 0 (HR stayed 540 under budget) |
| E6 (alternative) | =MAX(0,C6-B6) | 0, same as the IF version |
| C16 | =IF(B16>=$B$11,"Pass","Fail") | Pass (Lena scored exactly 70) |
The second part of the lab grades a staff safety test. The pass mark of 70 points is stored in its own cell, B11, and every result formula points to it: =IF(B14>=$B$11,"Pass","Fail"). The dollar signs make the reference absolute, so it stays on B11 as you copy the formula down to C19. When HR later decides that the pass mark should be 75, someone changes one cell and all six results update. Nobody has to open a formula, and nobody can forget one row.
Lena is the reason the operator matters. She scored exactly 70. The rule says a score of at least the pass mark passes, so the correct test is >=, and she passes. With > she would fail, and nobody would notice until she complained. Edge cases like this are where most real-world IF errors live, which is why the lab deliberately includes one.
How to do it in Excel, step by step
- Click the first result cell, D2. Type
=IF(. Excel shows a tooltip with the three arguments; the bold one is the argument you are typing now. - Write the test: click C2, type
>, click B2. Type a comma to move to the next argument. - Type the TRUE answer in double quotes,
"Over", then a comma, then the FALSE answer,"Within". Close the bracket and press Enter. - Select D2 again and double-click the small square in its bottom-right corner (the fill handle), or select D2:D9 and press Ctrl+D, to copy the formula to every department.
- In E2, type
=IF(C2>B2,C2-B2,0)and fill it down. Format E2:E9 as currency with Home > Number Format, or Ctrl+Shift+4 on Windows. - Type the pass mark 70 into B11. In C14, type
=IF(B14>=, click B11 and press F4 (Cmd+T on Mac) once to turn it into$B$11. Finish with,"Pass","Fail")and fill down to C19. - Test your logic: change B11 to 75 and check that Tom (76) still passes while Lena (70) now fails. Change it back.
- If a result surprises you, select the cell and use Formulas > Evaluate Formula. It shows the test being replaced by TRUE or FALSE, step by step.
- Select A1:C9 and choose Insert > Charts > Clustered Column. Click the chart title and type "Budget vs actual by department".
- Optional: highlight the Over cells with Home > Conditional Formatting > Highlight Cells Rules > Equal To, type Over and pick a light red fill.
From labels to insight
Look at the chart once the status column is filled in. The four departments that overspent, Marketing, IT, Customer care and E-commerce, are exactly the ones where the actual column is taller than the budget column. The IF formula and the chart agree, which is what you want: the label gives the reader a quick answer, and the chart gives them the size of the problem. E-commerce overspent the most, 4,800, while Customer care was only 1,150 over. A manager reading only the Status column would see four identical "Over" labels; the Overspend column and the chart add the context needed to prioritise.

Designing IF rules that survive real data
A formula that works on today’s data can still give wrong answers next month. The most common reason is the empty cell. Excel treats a blank cell as zero in a comparison, so if Finance has not yet entered its actual spend, =IF(C8>B8,"Over","Within") compares 0 with 15,000 and cheerfully reports Within. The label is technically correct and practically misleading, because the department has not reported at all.
There are two simple defences. The first is to make the missing data visible: =IF(C2="","Not reported",IF(C2>B2,"Over","Within")) checks for a blank before it checks the budget. You will meet this pattern of one IF inside another properly in the nested-IF lab; for now it is enough to know that the first test wins. The second defence is a quick count at the bottom of the column, for example =COUNTBLANK(C2:C9), so that anyone reading the report sees at a glance how many departments are still missing.
A related habit is to keep the result type consistent. A status column should only ever contain the labels you defined, and an amount column should only ever contain numbers. Mixing them, for example returning "n/a" in the overspend column, breaks every SUM and chart that uses the column. If a value is genuinely not applicable, return 0 or an empty string and explain the rule in a note next to the table.
Common mistakes and how to spot them
- Reversed test.
=IF(C2<B2,"Over","Within")labels the thrifty departments as over budget. Check one row you can verify in your head, such as Marketing, before you trust the column. - Wrong boundary operator. Using
>where the rule says "at least" fails anyone exactly on the limit. Always test the edge value, like Lena’s 70 or the Warehouse’s exact budget. - Missing quotes around text.
=IF(C2>B2,Over,Within)returns #NAME?. Text answers need double quotes; cell references and numbers do not. - Numbers in quotes.
=IF(C2>B2,"0",…)returns the text "0", which SUM ignores. Check alignment: text is left-aligned by default, numbers right-aligned. - Relative reference to a limit cell.
=IF(B14>=B11,…)becomesB15>=B12in the next row, which compares against an empty cell. Use$B$11. - Typing the limit into the formula.
=IF(B14>=70,…)works today but hides the rule. Put limits, rates and thresholds in labelled input cells. - Comparing numbers stored as text. If the imported actuals are text while the budgets are numbers, a test like
C2>B2is TRUE for every row, because Excel ranks any text above any number. Convert the data to numbers first (Data > Text to Columns > Finish).
Quick reference: functions and shortcuts used
| Function / shortcut | Syntax or keys | What it is for |
|---|---|---|
| IF | IF(logical_test, value_if_true, [value_if_false]) | Returns one of two results depending on a test |
| MAX | MAX(0, C2-B2) | Shortcut for "the difference, but never below zero" |
| Comparison operators | = <> > < >= <= | Build the logical test |
| Absolute reference | $B$11, toggle with F4 (Cmd+T on Mac) | Keeps a limit cell fixed when you copy the formula |
| Fill down | Ctrl+D, or double-click the fill handle | Copies the first formula to the rest of the column |
| Evaluate Formula | Formulas > Evaluate Formula | Steps through a formula to show how the test is decided |
| Insert chart | Alt+F1 (embedded) or F11 (new sheet) | Quick default chart of the selected data |
| Conditional formatting | Home > Conditional Formatting | Colours cells by the same rule your IF uses |
Real-world uses of a simple IF
- Budget control. Flag cost centres over budget each month and calculate the overspend for the management pack, exactly as in this lab.
- Sales targets.
=IF(C2>=B2,"Target met","Below target")on a sales-rep list, with the target in its own column so it can differ per rep. - Stock reorder alerts.
=IF(B2<=C2,"Reorder","OK")compares stock on hand with the reorder point for each product. - Training and compliance. Grade tests against a pass mark stored in one cell, so HR can change the standard without editing formulas.
- Shipping and discounts.
=IF(D2>=$H$1,0,$H$2)charges a shipping fee only when an order is below the free-shipping threshold in H1, with the fee itself in H2.
What you will build in the rest of this course
This first lab is free. The seven paid labs build on it with the same company and increasingly realistic rules, and every cell is checked instantly by the Coach.
IF with AND, OR & NOT: Eligibility Rules. Real policies rarely depend on one condition. You turn Brightline’s HR policy into formulas for bonus eligibility, training needs and a location allowance, including a bonus that needs two conditions plus one of two others.
Nested IF vs IFS: Grade Bands & Commission Tiers. When there are more than two outcomes, you need more than one test. You grade customer-satisfaction scores with a nested IF, pick commission rates with the cleaner IFS, calculate the commission and label each rep’s quota status.
SWITCH, CHOOSE & XLOOKUP: Replacing Nested IFs. Long chains of IF are hard to maintain. You translate region codes with SWITCH, price shipping with CHOOSE and replace a five-level IF with an approximate-match XLOOKUP on a tier table.
IF with Text: SEARCH, LEFT, EXACT & LEN. You categorise web-shop lines by a word in the description, route them by the SKU prefix, check promo codes case-sensitively and flag broken records.
IF with Dates: Overdue Invoices & Weekend Deliveries. You label receivables as Paid, Overdue or Open, count the days overdue, spot weekend deliveries with WEEKDAY and move them to the following Monday.
Error Handling: IFERROR vs IFNA, ISBLANK & ISNUMBER. You make lookups show a clean "Not listed" instead of #N/A, keep totals free of #VALUE!, write data checks and learn why the narrower IFNA is often the safer wrapper.
Mid-course project: Logic-Driven Status Dashboard with COUNTIFS, SUMIFS & IF Arrays. You pull it all together into a store dashboard with a three-level status, counts per region, the sales gap of stores that are behind, conditional highlights and a stacked column chart.
Summary
IF asks one TRUE-or-FALSE question and returns one of two answers. Write the test with the operator that matches the wording of the rule, put text answers in quotes, let IF return calculations when you need a number, and keep limits in their own absolutely referenced cells. Then test the edge cases, because that is where logical formulas go wrong.
Now scroll back up to the free lab and put it into practice: flag Brightline’s over-budget departments, calculate the overspend, grade the safety test and build the chart. The Coach checks each answer as you go, and it will tell you if you fall into one of the traps described above.
Frequently asked questions
How do I write an IF formula in Excel?
Use =IF(logical_test, value_if_true, value_if_false), for example =IF(C2>B2,"Over","Within"). Excel returns the second argument when the test is TRUE and the third when it is FALSE.
How do I use IF to show over or under budget?
Compare actual with budget: =IF(C2>B2,"Over","Within"). To show the amount instead, use =IF(C2>B2,C2-B2,0) or the equivalent =MAX(0,C2-B2).
What is the difference between > and >= in an IF formula?
The > operator means strictly greater than, so a value equal to the limit returns FALSE. The >= operator means "at least", so a value exactly on the limit returns TRUE. Choose the one that matches the wording of your rule.
Why does my IF formula return #NAME?
Most often a text answer is missing its double quotes, as in =IF(C2>B2,Over,Within). Put text in quotes: "Over". A misspelled function name causes the same error.
Why does my IF formula show FALSE instead of a blank?
You left out the value_if_false argument, so Excel returns FALSE when the test fails. Add a third argument such as "" to show an empty cell.
Can an IF formula return a calculation instead of text?
Yes. Any of the two answers can be a number, a cell reference or a full calculation, for example =IF(C2>B2,C2-B2,0). Just do not put numbers in quotes, or they become text.
Keep going: Excel IF & Logical Functions: From Simple IF to IFS, SWITCH & Nested Logic
This free lab is lesson 1 of 20. Unlock the other 19 hands-on labs, the final exam and your certificate for a one-time CHF 9.90.
- IF with AND, OR & NOT: Eligibility Rules
- Nested IF vs IFS: Grade Bands & Commission Tiers
- SWITCH, CHOOSE & XLOOKUP: Replacing Nested IFs
- IF with Text: SEARCH, LEFT, EXACT & LEN
- IF with Dates: Overdue Invoices & Weekend Deliveries
- Error Handling: IFERROR vs IFNA, ISBLANK & ISNUMBER
- Mid-course project: Logic-Driven Status Dashboard with COUNTIFS, SUMIFS & IF Arrays
- Logic as Numbers: TRUE×1, Double Negation & SUMPRODUCT Counts
- Tolerance Rules: ABS with an Amount Limit and a Percent Limit
- Progressive Tiers: Marginal Rebates with MIN and MAX
- Boundary Traps: Round Before You Compare
- Two-Key Rule Tables: INDEX & MATCH Instead of an IF Pyramid
- Decision Order: Exceptions First in a Returns Policy
- Logic with Lists: Holiday Checks with COUNTIF & Shift Premiums
- Conditional Statistics: AVERAGEIFS, MAXIFS & MINIFS with Exclusions
- Testing Your Logic: Edge-Case Test Grids & Mismatch Counts
- A Rule Engine for Data Checks: Count Broken Rules & List the Reasons
- LET: Name the Parts of a Long Logical Formula
- Final Project: Wholesale Order Approval Dashboard