Sub topic 13
SUMIF, COUNTIF, and AVERAGEIF: how they differ
Assume you know how to enter formulas and use ranges such as A2:A100. This chapter focuses on the single-condition functions. Each function checks one range against one criterion. The plural forms, such as SUMIFS, support several criteria and use a different argument order for the result range.
The three single-condition functions
Use the function that matches the result you need:
| Function | Purpose | Syntax |
|---|---|---|
| `COUNTIF` | Counts matching cells or rows | `COUNTIF(range, criterion)` |
| `SUMIF` | Adds values that match | `SUMIF(range, criterion, [sum_range])` |
| `AVERAGEIF` | Averages values that match | `AVERAGEIF(criteria_range, criterion, [average_range])` |
The first range is always the range that Sheets checks. The criterion can be text, a number, a comparison such as ">=10", or a cell reference.
Suppose column A contains regions and column E contains revenue:
=COUNTIF(A2:A100, "West")
=SUMIF(A2:A100, "West", E2:E100)
=AVERAGEIF(A2:A100, "West", E2:E100)These formulas count West rows, add West revenue, and average West revenue.
Optional result ranges
COUNTIF needs only the checked range because it returns a count. SUMIF and AVERAGEIF can use a separate result range.
If you omit sum_range, SUMIF adds the cells in its checked range:
=SUMIF(D2:D100, ">=10")If you omit average_range, AVERAGEIF averages the matching cells in its checked range:
=AVERAGEIF(D2:D100, ">=10")Use a separate result range when the condition and result are in different columns. For example, check units in column D but average revenue in column E.
Argument order differs from the plural forms
The single-condition functions begin with the range being checked. SUMIF and AVERAGEIF put the optional result range last.
The plural functions put the result range first:
=SUMIFS(E2:E100, A2:A100, "West")
=AVERAGEIFS(E2:E100, A2:A100, "West")This difference is a common source of incorrect formulas. With SUMIF, write the condition range first. With SUMIFS, write the sum range first.
Choosing the right function
Comparison criteria use a quoted operator:
=COUNTIF(D2:D100, ">=10")
=SUMIF(E2:E100, ">1000")To make the threshold editable, join the operator to a cell:
=SUMIF(D2:D100, ">"&H1, E2:E100)Here, changing H1 changes the threshold without editing the formula.
Common errors
The checked range and result range should cover corresponding rows. If one starts at row 2 and another starts at row 3, results can be wrong even when Sheets accepts the formula. Also check whether numbers are stored as numbers and dates are real dates rather than text.
AVERAGEIF returns #DIV/0! when no cells match. Use IFERROR when a blank result or message is more useful:
=IFERROR(AVERAGEIF(A2:A100, G2, E2:E100), "No matches")Exercise
Which formula averages revenue in E2:E100 for rows whose region in A2:A100 is "West"?
Show answer
=AVERAGEIF(A2:A100, "West", E2:E100)