top of page

You are learning IF function in MS Excel

How do I use the IF function to look up values based on conditions?

You can combine the IF function with other lookup functions like VLOOKUP or INDEX/MATCH to create conditional lookups in Excel. Here's a breakdown:

Scenario: Imagine you have a table with product codes (A) and corresponding prices (B). You want to display a discount price (C) based on a condition:

* If the product code starts with "A" (e.g., A101), apply a 10% discount.
* Otherwise, display the regular price (B).

Formula with VLOOKUP and IF:

```excel
=IF(LEFT(A2,1)="A",B2*0.9,B2)
```

Explanation:

1. `LEFT(A2,1)`: This part extracts the first character from the product code in cell A2.
2. `"A"`: We compare the extracted character to see if it's "A".
3. `IF` function:
- Condition: `LEFT(A2,1)="A"` checks if the first character is "A".
- Value if True: If true, it multiplies the price in B2 by 0.9 (10% discount).
- Value if False: If false, it simply displays the regular price from B2.

Alternative with INDEX/MATCH:

```excel
=IF(LEFT(A2,1)="A",INDEX(B:B,MATCH(A2,A:A,0)),B2)
```

Explanation:

1. Similar to the VLOOKUP example, it checks if the first character of the code is "A".
2. `INDEX/MATCH` combination:
- `INDEX(B:B,MATCH(A2,A:A,0))`: This part finds the corresponding price in column B based on the matching product code in column A.
- `MATCH(A2,A:A,0)`: This finds the row position of the product code (A2) within column A (using exact match - 0).
- `INDEX(B:B,...)`: This then uses that row position to return the corresponding price from column B.
3. `IF` function: Similar logic as the VLOOKUP example, displaying the discounted price if the condition is true, otherwise the regular price.

These are just two examples. You can adapt the formula based on your specific data and conditions. Remember to adjust cell references and modify the discount percentage as needed.

bottom of page