Logic Functions 2

Excel logic functions are powerful tools to evaluate data. In addition to the IF logic function, the OR and AND functions can expand the logic criteria when used in conjunction with the IF function.

For this chapter, we will reference data from **Figure 33.1**, including employee names, genders, positions, tenures, GPAs, and salaries. We want to evaluate the data in varying scenarios to award employees with a bonus.

Use this workbook for the chapter.

In the first scenario, we want to give employees who have a tenure greater than 15 years $5,000, and $1,000 for those with a tenure of 15 and less. We can evaluate the criteria using the IF function.

- Type
**=IF**and a left parenthesis (**(**) to start the function on the first employee's row. - Select the cell containing the employee's tenure data.
- Type
**>15**to indicate a greater than 15 evaluation and type a comma (**,**). - Type
**5000**as the bonus value for the employee if the greater than evaluation is true. - Type a comma (
**,**). - Type
**1000**as the bonus value for the employee if the greater than evaluation is false. - Type a right parenthesis (
**)**) to close the formula. - Press
**Enter**to complete the function (shown as**=IF(E3>15,5000,1000)**in**Figure 33.2**).

If we want to evaluate multiple criteria and award the employee based on tenure or GPA, we can use the OR function within an IF function. In this example, we will use an OR function to check if the employee's tenure is greater than 15, or if their GPA is greater than 3.5, and award them with $5,000 if one of the conditions is true. Otherwise, the employee will receive $1,000 if neither tenure nor GPA is greater than the set value.

- Type
**=IF**and a left parenthesis (**(**) to start the function on the first employee's row. - Type
**OR**and a second left parenthesis (**(**). - Select the cell containing the employee's tenure data.
- Type
**>15**to indicate a greater than 15 tenure evaluation and type a comma (**,**). - Select the cell containing the employee's GPA data.
- Type
**>3.5**to indicate a greater than 3.5 GPA evaluation. - Type a right parenthesis (
**)**) to close the OR formula. - Type a comma (
**,**). - Type
**5000**as the bonus value for the employee if the greater than evaluation is true. - Type a comma (
**,**). - Type
**1000**as the bonus value for the employee if the greater than evaluation is false. - Type a right parenthesis (
**)**) to close the IF formula. - Press
**Enter**to complete the function (shown as**=IF(OR(E3>15,F3>3.5),5000,1000)**in**Figure 33.3**).

The AND function requires both criteria to be true. We will use this function to evaluate if the employee's tenure is greater than 15 and GPA is greater than 3.5 to determine if the employee receives a $5,000 bonus.

- Type
**=IF**and a left parenthesis (**(**) to start the function on the first employee's row. - Type
**AND**and a second left parenthesis (**(**). - Select the cell containing the employee's tenure data.
- Type
**>15**to indicate a greater than 15 tenure evaluation and type a comma (**,**). - Select the cell containing the employee's GPA data.
- Type
**>3.5**to indicate a greater than 3.5 GPA evaluation. - Type a right parenthesis (
**)**) to close the AND formula. - Type a comma (
**,**). - Type
**5000**as the bonus value for the employee if the greater than evaluation is true. - Type a comma (
**,**). - Type
**1000**as the bonus value for the employee if the greater than evaluation is false. - Type a right parenthesis (
**)**) to close the IF formula. - Press
**Enter**to complete the function (shown as**=IF(AND(E3>15,F3>3.5),5000,1000)**in**Figure 33.4**).

A nested IF function sets a condition within another IF function's true or false arguments. These may be chained multiple times to set degrees of logic. For example, we want to build a varying bonus amount based on the number of years an employee has been with the company. If the employee has a tenure of 11–15 years, they will receive $2,000. Another employee with a tenure of 21–25 years will receive $6,000.

First, we'll build a table to determine every tenure range and bonus amount (see **Figure 33.5**). The first column will contain years beginning with five and increase in integrals of five until 30 years. The second column will contain bonus amounts beginning with $1,000 for five years and increase to $2,000, $5,000, $6,000, $7,500, and $10,000. We'll add a final row for 100 years with $10,000 for reference.

Then we'll write an IF function using the table. It will start by awarding $10,000 to employees with a tenure greater than 30 years, but if the logic is false (the employee's tenure is 30 or below), a new IF function will be inserted for the false argument and descend through the table's data. The chain of IF functions for false conditions will continue until the table's final values wherein the false argument returns zero for tenure below five.

- Type
**=IF**and a left parenthesis (**(**) to start the function on the first employee's row. - Select the cell containing the employee's tenure data.
- Type
**>**to indicate a greater than evaluation. - Select and anchor the table's cell containing
**30**to indicate a greater than 30 evaluation and type a comma (**,**). (See**Figure 33.5**) - Select and anchor the cell containing the bonus value for 30 years (
**$10,000**) and type a comma (**,**). - Type
**IF**and a left parenthesis (**(**) to insert a new IF argument if the greater than evaluation is false. - Repeat steps 2–6 for each value of Years and Bonus appropriately until the final value_if_false argument.
- Type
**0**(zero) as the final value_if_false argument. - Type six right parentheses (
**)**) to close all IF formulas. - Press
**Enter**to complete the function (**=IF(E8>$P$8,$Q$8,IF(E3>$P$7,$Q$7,IF(E8>$P$6,$Q$6,IF(E8>$P$5,$Q$5,IF(E8,$P$4,$Q$4,IF(E3>$P$3,$Q$3,0))))))**as the final formula).

However, a nested IF function can be complex and prone to errors. There is a time and place for nested IF functions, but there may be more efficient alternatives.

The Match and Index functions can achieve the same results as a nested IF function. We'll start with the Match function to identify the row in the **Figure 33.5** chart that closely matches the employee's tenure.

- Type
**=MATCH**and a left parenthesis (**(**) to start the function on the first employee's row. - Select the cell containing the employee's tenure data and type a comma (
**,**). - Select and anchor the table's range of cells containing year values and type a comma (
**,**). - Type
**1**to indicate an approximate less than match. - Type a right parenthesis (
**)**) to close the formula. - Press
**Enter**to complete the function (shown as**=MATCH(E3,$P$3:$P$9,1)**in**Figure 33.6**).

Now we need to add the Index function to return the value associated with the tenure match. To do it, we'll insert the Index function before Match and select the range of cells containing the bonus data for the lookup_value argument. The Match function will take the place of the Index function's lookup_array. Finally, the match type will be 1 to indicate an approximate less than match.

The results may be a little different from the nested IF function due to a difference in the evaluations. The nested IF function returned bonus amounts based on if the employee's tenure is greater than the table's Year values. Whereas the Index and Match functions return a bonus amount based on if the employee's tenure is less than or equal to the chart's values.

These functions will also result in an error if the employee's tenure is less than five because the chart does not include a row for years below five. One way to resolve this problem is to enclose the Index and Match operations with another function: IFERROR. The IFERROR function can be set to return zero if the other functions produce an error.

This content is provided to you freely by EdTech Books.

Access it online or download it at https://edtechbooks.org/bus_115_business_app/logic_functions_2.