The following figure shows the daily closing price for the Standard & Poor's 500 for the month of September 2004. A possible analysis is to see how many times the closing price was higher than the average for the month. Therefore, you need to calculate the average before you can compare any single price. Embed the AVERAGE function inside another function to calculate the average first.
When a function is nested inside another, the inner function is calculated first. Then that result is used as an argument for the outer function.
The COUNTIF function counts the number of cells in a range that meet a condition. The condition in this case is that any single value in the range is greater than (>) the average of the range. The formula in cell D7 is =COUNTIF(B5:B25, ">" & AVERAGE(B5:B25)). The AVERAGE function is evaluated first; then the COUNTIF function is evaluated, using the returned value from the nested function as an argument.Nested functions are best entered directly. The Insert Function dialog box does not make it easy to enter a nested function. Try one. In this example, you use the AVERAGE function to find the average of the largest values from two sets of numbers. The nested function in this example is MAX. You enter the MAX function twice within the AVERAGE function. Follow these steps:
-
Enter a few different numbers in one column.
-
Enter a few different numbers in a different column.
-
Click an empty cell where you want the result to appear.
-
Type =AVERAGE( to start the function entry.
-
Type MAX(.
-
Click the first cell in the second set of numbers, press the mouse button, and drag over all the cells of the first set.
The address of this range enters into the MAX function.
-
Enter a closing parenthesis to end the first MAX function.
-
Enter a comma (,).
-
Once again, type MAX(.
-
Click the first cell in the second set of numbers, press the mouse button, and drag over all the cells of the second set.
The address of this range enters into the MAX function.
-
Enter a closing parenthesis to end the second MAX function.
-
Enter a ).
This ends the AVERAGE function.
-
Press Enter.
When you use nested functions, the outer function is preceded with an equal sign (=) if it is the beginning of the formula. Any nested functions are not preceded with an equal sign.
You can nest functions up to 64 levels.