Advanced Excel for Data AnalystsLesson 12 of 49
Lesson 12 of 49

Logical Branching & Multi-Tier Rules: IF, IFS, AND, OR, XOR

Overview & Learning Objectives

Logical formulas let your spreadsheet make decisions automatically. If an order exceeds ₹1,000, apply a 15% discount; otherwise, apply 5%. We combine IF, IFS, AND, OR, and XOR to handle multi-tiered business logic with complete accuracy.

  • Write clear IF statements with condition, value_if_true, and value_if_false.
  • Use modern IFS to replace messy, deeply nested IF statements.
  • Combine conditions with AND (all must match) and OR (at least one matches).
  • Deploy XOR for mutually exclusive business promo rules.

Industry Standard

Standard: Business rules engines, commission structures, and credit scoring pipelines in banks and FinTechs are built on structured logical branching formulas.

Real-World Example: Pizza Hub Order Discounts & Priority Flags

At Pizza Hub, delivery orders over ₹800 get "Free Delivery", orders between ₹400 and ₹800 pay ₹40, and orders under ₹400 pay ₹60. Plus, VIP members get special perks. Logical formulas automate this calculation instantly for every customer bill.

Order IDOrder Value (₹)Customer VIP?Promo Code A?Promo Code B?
PZ-101950NoYesNo
PZ-102520NoNoNo
PZ-103310NoYesYes
PZ-104350Yes (VIP)NoYes

Functions Covered in this Chapter

Here is the definition, exact syntax, parameter breakdown, and real-world business example for each function covered in this chapter:

Function 1

IF Function

Definition: Evaluates a condition and returns one specified value if the condition is TRUE, and another specified value if it is FALSE.

Syntax:
=IF(logical_test, value_if_true, [value_if_false])
Parameters Breakdown:
  • logical_test: The comparison or condition to check (e.g. `B2 >= 500` or `C2 = "Yes"`).
  • value_if_true: The value, text, or formula returned when the condition is TRUE.
  • [value_if_false]: The value returned when the condition is FALSE. If omitted, Excel displays FALSE.
Real-World Example (Order Threshold Incentive):
Problem / Scenario: How do you award "Free Garlic Bread" if Order Value (B2) is >= ₹500, otherwise return "No Freebie"?
Formula: =IF(B2>=500, "Free Garlic Bread", "No Freebie")
Result: "Free Garlic Bread" (for PZ-101 at ₹950)
Why it works: Cell B2 is 950, which is >= 500 (TRUE), so IF outputs the value_if_true text.
Function 2

IFS Function

Definition: Evaluates multiple conditions sequentially without nesting multiple parentheses, returning the value for the first condition that evaluates to TRUE.

Syntax:
=IFS(logical_test1, value_if_true1, [logical_test2, value_if_true2], ..., [TRUE, default_value])
Parameters Breakdown:
  • logical_test1, value_if_true1: First condition and its corresponding result if TRUE.
  • logical_test2, value_if_true2: Second condition checked only if condition 1 was FALSE.
  • TRUE, default_value: Catch-all fallback placed at the end; executes if no previous condition was met.
Real-World Example (Tiered Delivery Fee Calculator):
Problem / Scenario: Charge ₹0 if Order >= ₹800, ₹40 if Order >= ₹400, and ₹60 for all remaining orders under ₹400.
Formula: =IFS(B2>=800, 0, B2>=400, 40, TRUE, 60)
Result: 0 (for PZ-101 at ₹950), 40 (for PZ-102 at ₹520), 60 (for PZ-103 at ₹310)
Why it works: IFS checks from left to right. Once a condition is TRUE, it returns the value and stops checking further.
Function 3

AND Function

Definition: Logical operator that evaluates up to 255 conditions and returns TRUE only if ALL conditions are TRUE. If any condition is FALSE, it returns FALSE.

Syntax:
=AND(logical1, [logical2], ...)
Parameters Breakdown:
  • logical1: First condition to evaluate.
  • [logical2], ...: Additional conditions that must also be TRUE.
Real-World Example (VIP High-Spender Discount):
Problem / Scenario: Give a 15% discount only if Order Value is >= ₹800 AND the customer is a VIP member.
Formula: =IF(AND(B2>=800, C2="Yes (VIP)"), B2*0.15, 0)
Result: 142.50 (for ₹950 VIP order), 0 (for non-VIP orders)
Why it works: AND ensures both requirements are strictly met before triggering the discount calculation.
Function 4

OR Function

Definition: Logical operator that evaluates conditions and returns TRUE if AT LEAST ONE condition is TRUE. Returns FALSE only when all conditions are FALSE.

Syntax:
=OR(logical1, [logical2], ...)
Parameters Breakdown:
  • logical1: First condition to evaluate.
  • [logical2], ...: Additional conditions to evaluate.
Real-World Example (Express Delivery Eligibility):
Problem / Scenario: Qualify an order for free express delivery if Order Value is >= ₹800 OR the customer has a VIP Pass.
Formula: =IF(OR(B2>=800, C2="Yes (VIP)"), "Free Express Delivery", "Standard Delivery")
Result: "Free Express Delivery" (even for PZ-104 at ₹350 because Customer is VIP)
Why it works: Since OR requires only one condition to match, a VIP member with an order under ₹800 still qualifies.
Function 5

XOR Function

Definition: Exclusive OR operator that returns TRUE if an ODD number of conditions are TRUE. For two conditions, it returns TRUE if exactly ONE is TRUE, and FALSE if both or neither are TRUE.

Syntax:
=XOR(logical1, [logical2], ...)
Parameters Breakdown:
  • logical1, logical2: Conditions being evaluated for mutual exclusivity.
Real-World Example (Mutually Exclusive Promo Code Check):
Problem / Scenario: Allow a promotional ₹50 coupon if a customer applied Promo Code A OR Promo Code B, but NOT both.
Formula: =IF(XOR(D2="Yes", E2="Yes"), 50, 0)
Result: 50 for PZ-101 (only Promo A) and PZ-104 (only Promo B); 0 for PZ-103 (both applied)
Why it works: XOR prevents promotional code abuse by blocking users who attempt to stack both coupons.

Common Mistakes & Limitations

  • Nesting 7 messy IF statements instead of using the modern, clean `IFS` or `SWITCH` function.
  • Checking conditions in the wrong order in IFS (e.g. checking `>= 400` before `>= 800` intercepts the 800 orders first).
  • Forgetting quotes around text criteria (e.g. writing `C2=Yes` instead of `C2="Yes"`), which causes `#NAME?` error.

Keyboard Shortcuts

ActionWindowsMac
Evaluate Formula Step-by-StepAlt + M + VFormulas Ribbon
Calculate Highlighted PortionF9 inside formula barF9
Exit Formula Bar without SavingEscEsc

Pro Tips & Modern Alternatives

  • Use `SWITCH()` when checking a single cell against a list of exact matches (e.g. Day 1 -> Monday, Day 2 -> Tuesday).
  • Use Boolean multiplication `=(B2>=800)*40` to perform conditional logic without IF functions.