This chapter will explore advanced logic or conditional functions in Excel, including CountIF, SumIF, AverageIF, and embedded IF statements in other functions. Each function is capable of evaluating a conditional expression and returning a designated value if true. Furthermore, these functions include a plural variation to analyze multiple criteria conditions to narrow down the result.

Use this workbook for the chapter.

The exercises in this chapter will use the dataset in **Figure 24.1** which includes employee name, gender, position, tenure, college GPA, and salary. We will add conditional inputs for reference to modify our calculations as needed, and we will have output cells for each function in this chapter.

In previous chapters, if we wanted to find the average salary of employees with a tenure of 10 years, we could use an IF function to check if the employee's tenure is greater than 10 and return their salary if true or nothing if false. We would copy the formula for each employee before using an Average function to evaluate the resulting range of cells.

However, instead of evaluating the condition and calculating the average separately, we can use IF logic functions to do both in one cell and vary the results based on our input cells.

The CountIF function can be used to evaluate a range of cells and return a count of items that meet a criteria. In this example, we will count the number of employees of a specific gender from **Figure 24.1**.

- Type
**=COUNTIF**and a left parenthesis (**(**) to start the function. - Select the range of cells containing the gender data and type a comma (
**,**). - Select the input cell containing the gender criteria.
- Type a right parenthesis (
**)**) to close the formula. - Press
**Enter**to complete the function (shown as**=COUNTIF(C3:C17,J4)**in**Figure 24.3**).

The CountIFS function works similarly to CountIF but allows for multiple criteria. If we need to count employees by gender and their college GPA, CountIFS can evaluate both criteria. In this example, we will need to check if GPA is greater than the specified input by including a greater than calculation in the function's formula.

- Type
**=COUNTIFS**and a left parenthesis (**(**) to start the function. - Select the range of cells containing gender data and type a comma (
**,**). - Select the input cell containing the gender criteria and type a comma (
**,**). - Select the range of cells containing college GPA data and type a comma (
**,**). - Type
**">"**and an ampersand (**&**) to indicate a greater than calculation will be performed. *Note:*Double quotation marks must be included around the greater than sign for the calculation to work correctly in this function.- Select the input cell containing the GPA criteria.
- Type a right parenthesis (
**)**) to close the formula. - Press
**Enter**to complete the function (shown as**=COUNTIFS(C3:C17,J4,F3:F17,">"&J6)**in**Figure 24.4**).

The SumIF function can be used to calculate the total number of values in a selected range of cells. The formula will prompt for the range of cells to evaluate, the criteria, and an optional range of cells to be added associated with the evaluated range. In this exercise, we want to calculate the total salaries of employees with a tenure greater than a specified number of years in the company.

- Type
**=SUMIF**and a left parenthesis (**(**) to start the function. - Select the range of cells containing tenure data and type a comma (
**,**). - Type
**">"**and an ampersand (**&**) to indicate a greater than calculation will be performed. - Select the input cell containing the tenure criteria and type a comma (
**,**). - Select the range of cells containing salary data.
- Type a right parenthesis (
**)**) to close the formula. - Press
**Enter**to complete the function (shown as**=SUMIF(tenure,">"&t_1,salary)**in**Figure 24.5**).

*Note:** *Cell ranges are named for ease of reference. You may consider naming ranges similarly. However, please note that the names are not required to complete the function successfully.

Similar to the CountIFS function, the SumIFS function works like SumIF but allows for multiple criteria conditions. For example, if we need to calculate the total salaries of employees of a specific gender and based on their college GPA, the SumIFS function can check for both criteria and add the salaries of those employees.

- Type
**=SUMIFS**and a left parenthesis (**(**) to start the function. - Select the range of cells containing salary data and type a comma (
**,**). - Select the range of cells containing gender data and type a comma (
**,**). - Select the input cell containing the gender criteria and type a comma (
**,**). - Select the range of cells containing GPA data and type a comma (
**,**). - Type
**">="**and an ampersand (**&**) to indicate a greater than or equal to calculation will be performed. - Select the input cell containing the GPA criteria.
- Type a right parenthesis (
**)**) to close the formula. - Press
**Enter**to complete the function (shown as**=SUMIFS(salary,gender,g_1,GPA,">="&gpa_1)**in**Figure 24.6**).

The AverageIF function is used to calculate an average of values that meet a specific criteria. The function prompts for a range to evaluate, criteria, and an optional range to calculate. In this case, we want to know the average tenure of employees that have a tenure below a specified number of years.

- Type
**=AVERAGEIF**and a left parenthesis (**(**) to start the function. - Select the range of cells containing tenure data and type a comma (
**,**). - Type
**"<"**and an ampersand (**&**) to indicate a less than calculation will be performed. - Select the input cell containing the tenure criteria.
- Type a right parenthesis (
**)**) to close the formula. - Press
**Enter**to complete the function (shown as**=AVERAGEIF(tenure,"<"&t_1)**in**Figure 24.7**).

Again, the AverageIFS function allows for multiple criteria to be set. In this example, we want to know the average tenure of employees by gender with a GPA greater than or equal to a specified number.

- Type
**=AVERAGEIFS**and a left parenthesis (**(**) to start the function. - Select the range of cells containing tenure data and type a comma (
**,**). - Select the range of cells containing GPA data and type a comma (
**,**). - Type
**">="**and an ampersand (**&**) to indicate a greater than or equal to calculation will be performed. - Select the input cell containing the GPA criteria and type a comma (
**,**). - Select the range of cells containing gender data and type a comma (
**,**). - Select the input cell containing the gender criteria.
- Type a right parenthesis (
**)**) to close the formula. - Press Enter to complete the function (shown as
**=AVERAGEIFS(tenure,GPA,">="&gpa_1,gender,g_1)**in**Figure 24.8**).

Not every statistical function includes an IF variation. For example, the standard deviation function (STDEV.S), which calculates the variability around the average of a dataset, does not have an IF logic variation. Instead, we need to embed an IF function within the standard deviation function to perform the calculation based on specific criteria. In this exercise, we'll embed an IF function to determine an employee salary dataset for a standard deviation calculation based on employee tenure greater than a specific number of years.

- Type
**=STDEV.S**and a left parenthesis (**(**) to start the function. - Type
**IF**and a second left parenthesis (**(**). - Select the range of cells containing tenure data.
- Type a greater than sign (
**>**). - Select the input cell containing the tenure criteria and type a comma (
**,**). - Select the range of cells containing salary data and type a comma (
**,**). - Type two double quotation marks (
**"**) to indicate a blank output. - Double quotation marks are typically used for a text string. In this case, no text is included, so the function will display a blank result if the logic argument is false.
- Type a right parenthesis (
**)**) to close the IF formula. - Type a second right parenthesis (
**)**) to close the STDEV.S formula. - Press
**Enter**to complete the function (shown as**=STDEV.S(IF(tenure>t_1,salary,""))**in**Figure 24.9**).

The Max function is another that can use an embedded IF function. If we want to know the maximum GPA of employees with a GPA greater than a specific value, we will need to use an IF formula to filter the results and identify the maximum value from the criteria.

- Type
**=MAX**and a left parenthesis (**(**) to start the function. - Type
**IF**and a second left parenthesis (**(**). - Select the range of cells containing GPA data.
- Type
**>=**to indicate a greater than or equal to calculation will be performed. - Select the input cell containing the GPA criteria and type a comma (
**,**). - Select the range of cells containing GPA data and type a comma (
**,**). - Type two double quotation marks (
**"**) to indicate a blank output. - Type a right parenthesis (
**)**) to close the IF formula. - Type a second right parenthesis (
**)**) to close the MAX formula. - Press
**Enter**to complete the function (shown as**=MAX(IF(GPA>=gpa_1,GPA,""))**in**Figure 24.10**).

The Min function may also use an embedded IF function to determine a minimum value from a filtered dataset. In this example, we want to know the minimum salary of employees that have a tenure greater than a specific number of years.

- Type
**=MIN**and a left parenthesis (**(**) to start the function. - Type
**IF**and a second left parenthesis (**(**). - Select the range of cells containing tenure data.
- Type
**>**to indicate a greater than calculation will be performed. - Select the input cell containing the tenure criteria and type a comma (
**,**). - Select the range of cells containing salary data and type a comma (
**,**). - Type two double quotation marks (
**"**) to indicate a blank output. - Type a right parenthesis (
**)**) to close the IF formula. - Type a second right parenthesis (
**)**) to close the MIN formula. - Press
**Enter**to complete the function (shown as**=MIN(IF(tenure>=t_1,salary,""))**in Figure 24.11).

The IF function can be embedded in other functions to determine data to be used based on the desired criteria. Remember to use it or the IFS function to narrow the data sample using specific conditions.

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_3.