Statistical IF Functions

Read these examples of how to use these different spreadsheet functions in the workplace. The learning objectives review how to use each type of function; the tables describe the syntax for each command type in detail.

The AVERAGEIF Function

The AVERAGEIF function performs the same mathematical calculation as the AVERAGE function. However, like the COUNTIF function, it allows you to define criteria to choose cells in a range used in the function output. The AVERAGEIF function differs from the COUNTIF function in that it allows you to define two cell ranges instead of one. The first range pertains to the criteria that will be used to select cells for the function output. The second range contains the values that will be used to calculate the arithmetic mean.

Table 1 defines the arguments in the AVERAGEIF and SUMIF functions.

Table 1 Arguments for the AVERAGEIF and SUMIF Functions
Argument Definition
Range The cells evaluated using the criteria argument.
Criteria We use criteria to evaluate the range of cells in the Range argument. We define this argument with a cell location, formula, number, text, or logical test. Text and logical tests must be enclosed in quotation marks.
[Average_range] or [Sum_range] The range of cells used to calculate the average when using the AVERAGEIF function, or the sum when using the SUMIF function. This argument is enclosed in brackets because it does not always need to be defined. If this argument is omitted, the function will use the range of cells in the Range argument to calculate the output.



We will use the AVERAGEIF function in the Portfolio Summary worksheet to calculate the average length of time for each investment type held.

These steps explain how to add this function to the worksheet:

  1. Click cell C4 on the Portfolio Summary worksheet.

  2. Click the Formulas tab on the Ribbon.

  3. Click the More Functions button in the Function Library group of commands.

  4. Place the mouse pointer over the Statistical option from the drop-down list (see Figure 1).

  5. Click the AVERAGEIF function, which will be near the top of the list of functions. This opens the Function Arguments dialog box.

  6. Click the Collapse Dialog button next to the Range argument on the Function Arguments dialog box (see Figure 4).

  7. Click the Investment Detail worksheet tab.

  8. Highlight the range A4:A18 on the Investment Detail worksheet and press the ENTER key on your keyboard.

  9. Click in the Range argument input box and place an absolute reference on the range A4:A18. This is done by typing a dollar sign ($) in front of the column letter and row number for both cells in the range.

  10. Press the TAB key on your keyboard to advance to the Criteria argument and type the cell location A4. The criteria for the function will be the investment type entered into cell A4 on the Portfolio Summary worksheet.

  11. Click the Collapse Dialog button next to the Average_range argument on the Function Arguments dialog box (see Figure 4).

  12. Click the Investment Detail worksheet tab.

  13. Highlight the range Q4:Q18 on the Investment Detail worksheet and press the ENTER key on your keyboard.

  14. Click in the Average_range argument input box and place an absolute reference on the range Q4:Q18. This is done by typing a dollar sign ($) in front of the column letter and row number for both cells in the range.

  15. Click the OK button at the bottom of the Function Arguments dialog box.

  16. Figure 4 shows the Function Arguments dialog box for the AVERAGEIF function that will be input into cell C4. Notice that absolute references are placed on the cell locations that define the Range and Average_range arguments. The function will evaluate the cells in the range A4:A18 using the value in cell A4 on the Portfolio Summary worksheet. When a cell in the range A4:A18 meets the criteria, the function will pull the cell location in the same row from the range Q4:Q18 and include it in the average calculation.

    Defined Arguments for the AVERAGEIF Function - Absolute reference added to ranges, definition for the Average_range argument

    Figure 4 Defined Arguments for the AVERAGEIF Function

  17. Copy the function in cell C4 and paste it into the range C5:C7 using the Paste Formulas option.

  18. Type an equal sign (=) in cell C8.

  19. Click the Investment Detail worksheet tab. Then click cell Q19 and press the ENTER key on your keyboard.


Figure 5
 shows the output of the AVERAGEIF function in the Average Months Owned column on the Portfolio Summary worksheet. The function calculates the average months owned in Column Q on the Investment Detail worksheet, where the investment type is equal to the description entered in the range A4:A7 on the Portfolio Summary worksheet.

AVERAGEIF Function Output on the Portfolio Summary Worksheet - cell reference ='Investment Detail'!Q19

Figure 5 AVERAGEIF Function Output on the Portfolio Summary Worksheet

Integrity Check

Matching Row Numbers for the Range and Average_range (or Sum_range) Arguments

When defining the Average_range argument for the AVERAGEIF function or the Sum_range argument for the SUMIF function, it is good practice to make sure the row numbers match the row numbers used in the Range argument.

For example, if the Range argument is defined with the range A4:A12, the range used to define the Average_range or Sum_range argument should begin with Row 4 and end with Row 12.

If the row numbers in these two arguments do not match, Excel will include the values only in the rows used to define the Range argument.

For example, if the Range argument is defined with the range A4:A12 and the Average_range (or Sum_range) argument is defined with the range D4:D20, only the values in cells D4:D12 will be included in the function output.

Skill Refresher: AVERAGEIF Function

  1. Type an equal sign: =

  2. Type the function name AVERAGEIF followed by an open parenthesis: (

  3. Define the range argument with a range of cells that will be evaluated using the criteria argument.

  4. Type a comma.

  5. Define the criteria argument with a cell location, number, text, or logical test. Text and logical tests must be enclosed in quotation marks.

  6. Type a comma.

  7. Define the Average_range argument with a range that contains values to be averaged. Excel will use the range argument to calculate the average if this argument is omitted.

  8. Type a closing parenthesis: )

  9. Press the ENTER key on your keyboard.