The IF function is the gateway to intelligent spreadsheets — formulas that make decisions based on data and return different results depending on conditions. An IF formula is the Excel equivalent of asking "if this is true, do that; otherwise, do something else." Once you master basic IF, you will progress to nested IFs, and then to the powerful logical functions AND, OR, NOT, IFS, SWITCH, and IFERROR — which let you test multiple conditions simultaneously and handle errors gracefully. These functions appear in payroll, grading, inventory management, compliance checking, and virtually every analytical spreadsheet.
IF tests a condition and returns one of two values depending on whether the condition is TRUE or FALSE.
| Argument | What It Is | Example |
|---|---|---|
| logical_test | Any expression that evaluates to TRUE or FALSE. Usually a comparison using =, <, >, <=, >=, or <> | B2>=50, C2="Pass", A2<>0 |
| value_if_true | What the formula returns when the test is TRUE. Can be a number, text in quotes, another formula, or blank ("") | "Pass", B2*1.15, 0, "" |
| value_if_false | What the formula returns when the test is FALSE. Optional — if omitted, returns FALSE. Best practice: always include it. | "Fail", 0, B2, "" |
| Task | Formula | Returns |
|---|---|---|
| Pass/Fail based on a score | =IF(B2>=50,"Pass","Fail") | "Pass" if B2 ≥ 50; "Fail" if less |
| Discount if quantity > 10 | =IF(B2>10,A2*0.9,A2) | 10% discount if qty > 10; full price otherwise |
| VAT-exempt or VAT at 15% | =IF(C2="Exempt",0,B2*0.15) | R0 if Exempt; otherwise 15% VAT |
| Show nothing if a cell is blank | =IF(A2="","",A2*1.15) | Blank if A2 empty; VAT-inclusive price if not |
| Overdue invoice flag | =IF(TODAY()>A2+30,"OVERDUE","Current") | "OVERDUE" if today is past due date; "Current" if not |
| Bonus calculation | =IF(D2>=$E$1,B2*0.1,0) | 10% bonus if sales meet target in E1; R0 otherwise |
IF(C2="Finance",...)IF(B2>50000,...) — using quotes would compare as text and give wrong resultsIF(A2="",...) or IF(A2="",...)IF(A2<>"",...)IF can return text, numbers, dates, formulas, or blank — in any combination in the true and false positions:
A nested IF places one IF formula inside another. This lets you test multiple conditions in sequence, assigning a different result to each outcome. Think of it as a chain of "else if" decisions.
Excel evaluates the conditions from left to right. As soon as a condition is TRUE, it returns that result and stops. If no condition is TRUE, it returns the last default_result.
AND returns TRUE only when all of its conditions are TRUE. If even one condition is FALSE, AND returns FALSE. It is used inside IF to test multiple conditions that must all be met simultaneously.
| Task | Formula |
|---|---|
| Pass only if BOTH theory AND practical ≥ 50 | =IF(AND(B2>=50,C2>=50),"Pass","Fail") |
| Bonus only if sales >= target AND attendance ≥ 90% | =IF(AND(D2>=$E$1,E2>=90%),"Bonus","No bonus") |
| Apply discount if quantity > 10 AND customer is VIP | =IF(AND(B2>10,C2="VIP"),A2*0.8,A2) |
| Flag record if name not blank AND amount > 0 | =IF(AND(A2<>"",B2>0),"Complete","Incomplete") |
| Working age check (18–65) | =IF(AND(C2>=18,C2<=65),"Eligible","Not eligible") |
OR returns TRUE when at least one of its conditions is TRUE. It only returns FALSE when ALL conditions are FALSE. Use OR when any one of multiple criteria is sufficient.
| Function | Returns TRUE When | Returns FALSE When |
|---|---|---|
| AND | ALL conditions are TRUE | Any ONE condition is FALSE |
| OR | ANY ONE condition is TRUE | ALL conditions are FALSE |
| Task | Formula |
|---|---|
| Flag if either field is blank (data quality) | =IF(OR(A2="",B2=""),"Incomplete","Complete") |
| Exempt if category is "Gift" or "Export" | =IF(OR(C2="Gift",C2="Export"),0,B2*0.15) |
| Approve if manager OR director signs off | =IF(OR(D2="Manager",D2="Director"),"Approved","Pending") |
| Weekend check (day 6=Sat or day 7=Sun) | =IF(OR(WEEKDAY(A2,2)=6,WEEKDAY(A2,2)=7),"Weekend","Weekday") |
| Priority if amount > R100k OR overdue > 60 days | =IF(OR(B2>100000,C2>60),"HIGH","Normal") |
NOT reverses a logical value — TRUE becomes FALSE and FALSE becomes TRUE. It is used when it is easier to define what something is not than what it is.
| Formula | Equivalent To | Practical Use |
|---|---|---|
=NOT(A2="Active") | =A2<>"Active" | TRUE when status is anything except "Active" |
=IF(NOT(ISBLANK(A2)),A2*1.15,"") | =IF(A2<>"",A2*1.15,"") | Calculate only for non-blank cells |
=IF(NOT(AND(B2>=50,C2>=50)),"Fail","Pass") | =IF(OR(B2<50,C2<50),"Fail","Pass") | NOT(AND) = OR of the opposites — logically equivalent |
NOT is less commonly used alone but becomes useful when combined with ISBLANK, ISNUMBER, ISTEXT, ISERROR, or complex AND conditions that are easier to express as their negative.
IFS tests multiple conditions in sequence and returns the result of the first TRUE condition. It replaces long nested IF chains with a cleaner, flat structure — far easier to read and maintain.
#N/A. To add a catch-all default, end with: TRUE, "default value"| Task | Formula |
|---|---|
| Leave entitlement by years of service | =IFS(C2>=10,25, C2>=5,20, C2>=1,15, TRUE,0)10+ years = 25 days; 5+ = 20; 1+ = 15; less = 0 |
| Credit rating category | =IFS(B2>=750,"Excellent", B2>=650,"Good", B2>=550,"Fair", TRUE,"Poor") |
| Delivery priority by days overdue | =IFS(D2>30,"URGENT", D2>14,"HIGH", D2>7,"MEDIUM", TRUE,"LOW") |
SWITCH compares a single expression against a list of values and returns the result paired with the first match. Unlike IFS which evaluates conditions, SWITCH tests one value for exact equality against alternatives — like a lookup table without VLOOKUP.
| Task | Formula |
|---|---|
| Translate day number to day name | =SWITCH(WEEKDAY(A2,2), 1,"Monday", 2,"Tuesday", 3,"Wednesday", 4,"Thursday", 5,"Friday", 6,"Saturday", 7,"Sunday") |
| Department code to full name | =SWITCH(B2,"FIN","Finance","HR","Human Resources","OPS","Operations","IT","Information Technology","Unknown") |
| Month number to quarter | =SWITCH(MONTH(A2), 1,"Q1",2,"Q1",3,"Q1", 4,"Q2",5,"Q2",6,"Q2", 7,"Q3",8,"Q3",9,"Q3", 10,"Q4",11,"Q4",12,"Q4") |
Formula errors like #N/A, #DIV/0!, #VALUE!, and #REF! are distracting and can cascade through a spreadsheet. IFERROR and IFNA intercept these errors and replace them with a friendlier alternative.
| Formula | What It Does |
|---|---|
=IFERROR(A1/B1, 0) | Returns 0 instead of #DIV/0! when B1 is zero |
=IFERROR(VLOOKUP(A2,$F$2:$G$50,2,0), "Not found") | Returns "Not found" instead of #N/A when the value is missing |
=IFERROR((B2-A2)/A2, "") | Returns blank instead of #DIV/0! when A2 is zero |
=IFERROR(INDEX(MATCH(...)), "No match") | Returns "No match" when INDEX/MATCH finds nothing |
IFNA catches only #N/A errors (the "not found" error). Other errors like #DIV/0! or #VALUE! are still displayed. Use IFNA instead of IFERROR when you want to see other errors (they might indicate real data problems) but hide "not found" gracefully.
The real power emerges when you combine AND, OR, NOT, and IFERROR with IF in the same formula to handle complex real-world decision logic.
Excel provides a family of IS functions that return TRUE or FALSE based on the type of content in a cell. They are particularly useful inside IF to handle mixed data types gracefully.
| Function | Returns TRUE When | Practical Use |
|---|---|---|
=ISBLANK(A2) | A2 is completely empty | Skip empty rows in a list; identify missing data |
=ISNUMBER(A2) | A2 contains a numeric value (including dates) | Verify numbers before calculating; catch text-stored numbers |
=ISTEXT(A2) | A2 contains text | Identify text entries in a column that should be numbers |
=ISERROR(A2) | A2 contains any error value (#N/A, #REF!, etc.) | Error detection; counting errors in a range |
=ISNA(A2) | A2 contains #N/A specifically | Detecting "not found" results from VLOOKUP or MATCH |
=ISLOGICAL(A2) | A2 contains TRUE or FALSE | Checking the output of logical tests |
=ISFORMULA(A2) | A2 contains a formula (not a static value) | Auditing whether a cell is a formula or a hardcoded value |
Q1: Write an IF formula that assigns a grade letter to a score in B2: A (90+), B (80–89), C (70–79), D (60–69), F (below 60).
✓ Using nested IF: =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C",IF(B2>=60,"D","F")))). Using IFS (cleaner): =IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",B2>=60,"D",TRUE,"F"). Both produce the same result. The conditions are tested from highest down so a score of 92 matches ≥90 first and returns "A" without evaluating the rest. The TRUE at the end of IFS is the catch-all default for anything below 60.
Q2: An employee qualifies for a year-end bonus if their performance rating (column C) is "Exceeds" or "Outstanding" AND they have worked for at least 6 months (column D = months employed). Write the IF formula to calculate 10% of their salary (column B) as bonus, or 0 if not eligible.
✓ =IF(AND(OR(C2="Exceeds",C2="Outstanding"),D2>=6),B2*0.1,0). The inner OR checks whether the rating is either "Exceeds" or "Outstanding". The AND ensures that BOTH the OR condition (good rating) AND the minimum service (6+ months) must both be true. If either fails, the AND is FALSE and the formula returns 0. If both pass, it returns 10% of the salary in B2.
Q3: A VLOOKUP formula in column D sometimes returns #N/A when a product code is not in the price list. Your manager wants the cell to show "Price TBC" instead of the error. Rewrite the formula to handle this.
✓ Wrap the VLOOKUP with IFNA: =IFNA(VLOOKUP(A2,$G$2:$H$100,2,0),"Price TBC"). IFNA catches only the #N/A error (not found) and replaces it with "Price TBC". If there is a genuine formula error (like a #VALUE! from a wrong data type), that still shows — alerting you to a real problem. If you want to catch ALL errors and show "Price TBC" for any issue, use IFERROR instead: =IFERROR(VLOOKUP(A2,$G$2:$H$100,2,0),"Price TBC").
Q4: You have a department code in B2 (possible values: "FIN", "HR", "OPS", "IT", "MKT"). Write a SWITCH formula that translates the code to the full department name. If the code is unknown, show "Unknown Department".
✓ =SWITCH(B2,"FIN","Finance","HR","Human Resources","OPS","Operations","IT","Information Technology","MKT","Marketing","Unknown Department"). SWITCH compares B2 against each value in sequence. When it finds a match, it returns the paired result. The last argument "Unknown Department" is the default returned when none of the codes match. This is much cleaner than nested IFs for exact-match lookups.
Q5: What is the difference between AND and OR? Give a real payroll example where you would use AND versus a real example where you would use OR.
✓ AND returns TRUE only when ALL conditions are true; OR returns TRUE when ANY ONE condition is true. AND example: An employee qualifies for overtime pay only if they are NOT a manager AND worked more than 45 hours that week — BOTH conditions must be met: =IF(AND(C2<>"Manager",D2>45),(D2-45)*E2*1.5,0). OR example: An employee is exempt from the medical aid deduction if they are on contract OR are working less than 20 hours per week — either one is sufficient: =IF(OR(C2="Contract",D2<20),0,B2*0.01).
Q6: A column of data should contain only numbers, but some cells have text entries (data entry errors). Write a formula using an IS function that flags each cell as "OK" or "Not a number".
✓ =IF(ISNUMBER(A2),"OK","✗ Not a number"). ISNUMBER(A2) returns TRUE if A2 contains any numeric value (whole number, decimal, date, time, percentage) and FALSE if it contains text, is blank, or contains an error. The IF then returns "OK" for valid numeric cells and "✗ Not a number" for everything else. To count the total number of text entries across a range, use: =COUNTIF(A2:A100,"*") — this counts cells with any text. Or more precisely: =SUMPRODUCT(--ISTEXT(A2:A100)) counts all text cells including those that don't match a specific pattern.