Logical functions: IF, AND, OR, NOT in MS Excel

Here’s a detailed explanation of logical functions in Excel with examples:


1. IF Function

The IF function is used to return one value if a condition is TRUE and another value if it’s FALSE.

Syntax:

=IF(logical_test, value_if_true, value_if_false)

Example:

ProductSalesTargetMet Target? (Formula)
Laptop12001000=IF(B2>=C2, "Yes", "No")
Mobile9001000=IF(B3>=C3, "Yes", "No")
  • Explanation:
    • If Sales (Column B) is greater than or equal to Target (Column C), return “Yes”; otherwise, return “No”.
    • Result:
      • Laptop: Yes
      • Mobile: No

2. AND Function

The AND function checks if all conditions are TRUE. If all are TRUE, it returns TRUE; otherwise, it returns FALSE.

Syntax:

=AND(logical1, logical2, ...)

Example:

ProductSalesTargetIn StockEligible for Bonus? (Formula)
Laptop12001000Yes=IF(AND(B2>=C2, D2="Yes"), "Yes", "No")
Mobile9001000Yes=IF(AND(B3>=C3, D3="Yes"), "Yes", "No")
  • Explanation:
    • Check if:
      • Sales (Column B) is greater than or equal to Target (Column C), AND
      • In Stock (Column D) is “Yes”.
    • If both conditions are TRUE, return “Yes”; otherwise, return “No”.
    • Result:
      • Laptop: Yes
      • Mobile: No

3. OR Function

The OR function checks if any condition is TRUE. If at least one condition is TRUE, it returns TRUE; otherwise, it returns FALSE.

Syntax:

=OR(logical1, logical2, ...)

Example:

ProductSalesTargetIn StockUnder Consideration? (Formula)
Laptop12001000No=IF(OR(B2>=C2, D2="Yes"), "Yes", "No")
Mobile9001000Yes=IF(OR(B3>=C3, D3="Yes"), "Yes", "No")
  • Explanation:
    • Check if:
      • Sales (Column B) is greater than or equal to Target (Column C), OR
      • In Stock (Column D) is “Yes”.
    • If either condition is TRUE, return “Yes”; otherwise, return “No”.
    • Result:
      • Laptop: Yes
      • Mobile: Yes

4. NOT Function

The NOT function reverses the logical value of its argument:

  • Returns TRUE if the argument is FALSE.
  • Returns FALSE if the argument is TRUE.

Syntax:

=NOT(logical)

Example:

ProductIn StockOut of Stock? (Formula)
LaptopYes=NOT(D2="Yes")
MobileNo=NOT(D3="Yes")
  • Explanation:
    • If In Stock (Column D) is “Yes”, NOT will return FALSE, meaning “Out of Stock” is FALSE.
    • If In Stock is “No”, NOT will return TRUE, meaning “Out of Stock” is TRUE.
    • Result:
      • Laptop: FALSE
      • Mobile: TRUE

Combination Example

You can combine these functions for more complex logic.

Scenario:

Check if Sales exceed Target AND the product is in stock, OR the Target is below 800.

Formula:

=IF(OR(AND(B2>=C2, D2="Yes"), C2<800), "Approved", "Not Approved")
ProductSalesTargetIn StockStatus
Laptop12001000YesApproved
Mobile9001000NoNot Approved