Sub topic 2
How the *IFS functions are built
SUMIFS, COUNTIFS, and AVERAGEIFS share one design. If you learn that design once, you can read and write all three. This chapter covers the shared structure. The next chapters cover each function in detail.
This chapter assumes you can enter and copy formulas, you know relative and absolute references, and you have used SUM, COUNT, and AVERAGE. It also assumes your data has headers in row 1 and one record per row.
The sample data
Every example in this tutorial uses a sales list. Headers are in row 1, and data runs from row 2 down to row 100. Only the first rows are shown here.
A: Date B: Region C: Product D: Amount E: Notes
2025-01-05 West Laptop 1200
2025-01-09 East Monitor 300 Backorder
2025-02-02 West Monitor 310
2025-02-14 North Laptop 1150 GiftTwo kinds of arguments
Each *IFS function takes two kinds of arguments:
- A criteria pair is a range to test plus a condition to test it against. For example,
B2:B100and"West"form one pair: look in column B for the text West. - A value range is the range whose numbers are added or averaged. COUNTIFS has no value range, because it counts rows instead of reading numbers.
A row is included only when it passes every criteria pair. Excel checks the pairs row by row, and each row either qualifies or does not. Then the function adds, counts, or averages the qualifying rows.
Correction: the diagram must use the required fence format. Here it is in full.
The three signatures
The functions differ only in how they treat the value range.
| Function | Syntax | Value range |
|---|---|---|
| SUMIFS | `SUMIFS(sum_range, range1, criteria1, [range2, criteria2], ...)` | First argument |
| COUNTIFS | `COUNTIFS(range1, criteria1, [range2, criteria2], ...)` | None |
| AVERAGEIFS | `AVERAGEIFS(average_range, range1, criteria1, [range2, criteria2], ...)` | First argument |
Each function accepts up to 127 criteria pairs. SUMIFS and AVERAGEIFS need at least one pair, and so does COUNTIFS.
Reading a formula
This formula totals the Amount column for rows where Region is West:
=SUMIFS(D2:D100, B2:B100, "West")Read it from left to right:
D2:D100is the value range. These are the numbers to add.B2:B100is the range to test."West"is the criteria. Only rows where column B equals West count.
With the four sample rows, the West rows are the Laptop sale of 1200 and the Monitor sale of 310, so the result is 1510.
The other two functions use the same pieces:
=COUNTIFS(B2:B100, "West", C2:C100, "Laptop")This formula has two pairs and no value range. It counts rows where Region is West and Product is Laptop. In the sample rows the answer is 1.
=AVERAGEIFS(D2:D100, B2:B100, "West")This formula starts with the value range, like SUMIFS. It returns the mean Amount for West rows. In the sample rows that is (1200 + 310) / 2 = 755.
Why the order matters
The order of arguments is the most common source of mistakes. The older single-condition functions SUMIF and AVERAGEIF put the value range last: SUMIF(range, criteria, sum_range). SUMIFS and AVERAGEIFS put it first. If you move between the two families, you can swap arguments without noticing.
Excel does not always flag the mistake. Suppose you write =SUMIFS(B2:B100, "West", D2:D100). Excel sees "West" where it expects a range, and it returns an error. In other swaps the formula runs and quietly returns the wrong number, often 0.
Ranges must have the same shape
All ranges in one formula must have the same number of rows and columns. The value range and every criteria range are checked against each other. Excel matches them position by position, so the third cell of the criteria range lines up with the third cell of the value range.
This formula fails because column D has 99 rows in the range and column B has 98:
=SUMIFS(D2:D100, B2:B99, "West")The result is #VALUE!. The ranges do not need to sit in the same columns or on the same rows, but they must be the same size. A later chapter covers this error in more detail.
What criteria can look like
A criteria argument is a value to match, and it can take several forms. Text goes in quotes, as in "West". A number can be written without quotes, as in 1200. A cell reference such as G1 takes the value from that cell. A comparison operator is part of a quoted string, as in ">=1000". Later chapters cover each form.
Two rules apply to every form:
- Text matching ignores letter case, so
"west"matches West. - A criteria pair that mentions the same range as another pair is allowed. You will use this to set both ends of a numeric or date range.
Same ranges, different functions
Because the three functions share one structure, you can change the function without rewriting the conditions. Start with a COUNTIFS that returns the number of rows you expect. Then change the function name and add a value range at the front to get the total or the average for exactly those rows.
For example, the count of West rows is =COUNTIFS(B2:B100, "West"). The sum is =SUMIFS(D2:D100, B2:B100, "West"), and the average is =AVERAGEIFS(D2:D100, B2:B100, "West"). The criteria pair is the same in all three. Comparing the count with the sum and average is also a quick check that your criteria select the rows you intended.
Exercise
A colleague writes =SUMIFS(B2:B100, "East", D2:D100) to total Amount for East rows. Name the problem and write the corrected formula.
Show answer
The value range must come first, followed by each range and its condition. The formula puts the criteria before the criteria range and places the value range in the wrong position. The corrected formula is =SUMIFS(D2:D100, B2:B100, "East").
Exercise
Using the four sample rows, what does =COUNTIFS(B2:B100, "West", C2:C100, "Monitor") return, and what does =AVERAGEIFS(D2:D100, B2:B100, "West", C2:C100, "Monitor") return?
Show answer
Both formulas select the same single row, the West Monitor sale of 310. COUNTIFS returns 1 and AVERAGEIFS returns 310.