The Excel AVERAGEIF function calculates the average value from a range of cells with a given condition. The AVERAGEIF function is useful for calculating the average of subset of an overall dataset (with a single criteria).
=AVERAGEIF(range, criteria, [average_range])
range = the range of data to test the criteria against (if the average_range is left blank, then this range is also used for the average calculation)
criteria = the criteria to test against the range of data
average_range = [optional] the range of cells to calculate the average from if the condition(s) are true
The AVERAGEIF formula returns the mathematical average of the average_range (or range if average_range is blank) for the cells that meet the condition defined by the criteria.
In the example above the AVERAGEIF formula in cell N7 calculates average of the range of cells between I6:I35, which is the average age of the college applicants in the example dataset, when the applicant is from the country US, as defined by the cell reference M7.
The resulting average of US applicants is returned in cell N7, 25.9 years.