Lesson 3.6 – Logical Functions (IF, AND, OR)
Logical functions allow Excel to make decisions based on conditions. They are essential for building dynamic spreadsheets, validating data, and creating automated calculations. In questa lezione impari tre funzioni fondamentali: IF, AND e OR.
1. IF – Make Decisions
IF checks a condition and returns one value if the condition is true and another value if it is false.
Syntax:
=IF(condition, value_if_true, value_if_false)
Example:
=IF(A2 >= 50, "Pass", "Fail")
IF is used for grading, approvals, thresholds, flags, and conditional labels.
2. AND – Check Multiple Conditions
AND returns TRUE only if all conditions are true.
Syntax:
=AND(condition1, condition2, ...)
Example:
=AND(A2 >= 50, B2 >= 50)
AND is useful for combined requirements, such as minimum scores or multi-step validations.
3. OR – Check Alternative Conditions
OR returns TRUE if at least one condition is true.
Syntax:
=OR(condition1, condition2, ...)
Example:
=OR(A2 = "Yes", B2 = "Yes")
OR is ideal when multiple acceptable options exist.
4. Combining IF with AND/OR
You can combine logical functions to create powerful conditions.
Example with AND:
=IF(AND(A2 >= 50, B2 >= 50), "Approved", "Rejected")
Example with OR:
=IF(OR(A2 = "Gold", A2 = "Silver"), "Priority", "Standard")
These combinations are widely used in business rules and data validation.
5. Practical Example
Suppose you manage a list of students with two exam scores:
- Score 1 in column A
- Score 2 in column B
Rules:
- Pass if both scores ≥ 60
- Borderline if at least one score ≥ 60
- Fail otherwise
Formulas:
Pass:
=IF(AND(A2>=60, B2>=60), "Pass", "")
Borderline:
=IF(OR(A2>=60, B2>=60), "Borderline", "")
Fail:
=IF(AND(A2<60, B2<60), "Fail", "")
6. Common Mistakes to Avoid
- Using text without quotation marks ("Yes")
- Confusing AND with OR
- Forgetting that IF needs three arguments
- Using commas instead of colons in ranges
7. Practical Exercise
Practice logical functions with the following steps:
- Create a worksheet named Lesson_3_6_Practice.
- Enter two numeric columns (A and B).
- Use IF to label values above 100 as “High”.
- Use AND to check if both values exceed 50.
- Use OR to check if at least one value is zero.
- Combine IF + AND to create a pass/fail rule.
Internal Links
- Lesson 3.4 – Counting Functions (COUNT, COUNTA, COUNTBLANK)
- Lesson 3.5 – Text Functions (LEFT, RIGHT, MID, LEN, CONCAT)
- Lesson 3.7 – Next Module Introduction
Comments
Post a Comment