Sub topic 4
SUMIFS: Sum Range First, Then Criteria Pairs
Prerequisites
This chapter assumes you can enter formulas in Excel and know the difference between relative references (A5) and absolute references ($A$5). It also assumes you have a flat data table: one row per transaction, one column per field, with the same kind of value in every cell of a column. The earlier chapters in this tutorial cover that layout and the choice between totaling and looking up.
What SUMIFS does
SUMIFS adds up the numbers in one column, but only for rows that pass every test you give it. Use it when many rows can belong to one answer, such as all the ledger lines for one account.
The function has this shape:
SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)The first argument is the column you want to add up. Every argument after that comes in pairs. Each pair has a range to test and a condition to test it against. A row is included only when it passes all of the pairs. This is an AND test. SUMIFS has no built-in OR.
Here is the basic formula from the model:
=SUMIFS(Data!$F$2:$F$5000, Data!$B$2:$B$5000, $A5)Read it from left to right:
Data!$F$2:$F$5000is the sum range. It holds the amounts.Data!$B$2:$B$5000is the criteria range. It holds the account for each row.$A5is the criterion. It holds the account name you want on this row of the report.
Excel checks each row of column B. When the value equals the text in $A5, it adds the matching amount from column F to the total.
Why the sum range comes first
The order is the most common source of mistakes for people who know SUMIF. In the older SUMIF, the sum range comes last and is optional. In SUMIFS, the sum range comes first and is required. If you copy the habits of SUMIF into SUMIFS, the formula either returns an error or totals the wrong column.
| Function | Argument order |
|---|---|
| `SUMIF` | range, criteria, sum_range |
| `SUMIFS` | sum_range, criteria_range1, criteria1, criteria_range2, criteria2, ... |
Use SUMIFS even when you have only one condition. The order is consistent, and adding a second condition later means adding one more pair at the end.
The ranges must match in size
Every range in the formula must have the same number of rows and the same number of columns. In the example above, all three ranges run from row 2 to row 5000. If one range ended at row 4999, Excel would return #VALUE!.
Keep the ranges aligned by writing them with the same start and end rows. Anchor them with dollar signs, as in $F$2:$F$5000, so they do not shift when you copy the formula down or across. The criterion $A5 is different. It locks the column but leaves the row free, so each row of the report reads its own account name.
Adding a second condition
A second pair narrows the result. The next formula totals one account for one month:
=SUMIFS(Data!$F$2:$F$5000, Data!$B$2:$B$5000, $A5, Data!$D$2:$D$5000, ">=" & C$3, Data!$D$2:$D$5000, "<=" & EOMONTH(C$3,0))This formula has three pairs:
- Column B must equal the account in
$A5. - Column D, the date, must be on or after the first day of the month in
C$3. - Column D must also be on or before the last day of that month.
EOMONTH(C$3,0)returns the month-end date.
The date column appears twice. That is normal. A date range needs one lower bound and one upper bound, and each bound is its own pair.
In C$3, the row is locked and the column is free. You can copy the formula to the right and each column picks up its own month header. In $A5, the column is locked and the row is free. You can copy the formula down and each row picks up its own account. This mixed anchoring lets one formula fill the whole grid.
The next chapter covers operators, wildcards, and dates in more detail. This chapter only uses them to show how pairs combine.
A worked example
Suppose the Data sheet holds these rows.
| Row | Account | Category | Date | Amount |
|---|---|---|---|---|
| 2 | Salaries | Opex | 2026-01-15 | 5,000 |
| 3 | Salaries | Opex | 2026-02-15 | 5,200 |
| 4 | Rent | Opex | 2026-01-01 | 2,000 |
| 5 | Software | Opex | 2026-01-20 | 300 |
A report cell for Salaries in January uses the two-date formula above. Excel tests row 2: the account is Salaries, and January 15 falls between January 1 and January 31, so it adds 5,000. Row 3 has the right account but a February date, so it fails the date test. Rows 4 and 5 fail the account test. The result is 5,000.
If you leave out the date pairs, the same cell returns 10,200, because both salary rows pass.
How a row is tested
The diagram shows the decision for one row of data.
Excel repeats this for every row in the range and returns the running total.
Behaviors to know
Text in the sum range is ignored. If a cell in the sum range holds text, even a number stored as text, SUMIFS skips it without any warning. Your total comes out low and nothing flags it. Numbers pasted from another system are the usual cause.
Matching is not case sensitive. salaries and Salaries count as the same account.
Trailing spaces break matches. "Rent " with a space does not equal "Rent". The row is silently excluded.
A criterion of a blank cell behaves oddly. If $A5 is empty, the criterion is treated as zero, not as "match blank rows". Rows with an empty account are not matched. Keep the label column complete.
No match returns 0, not an error. This is useful for reports, but it hides problems. An account that is misspelled in the report returns 0 and looks like a valid empty account.
Closed workbooks cause trouble. SUMIFS that refers to another workbook returns #VALUE! when that workbook is closed. Keep the data on a sheet in the same file.
Bounded ranges
The example uses rows 2 to 5000 instead of whole columns. A bounded range is easy to audit, because you can see exactly what is included. Whole-column references such as Data!F:F also work, and SUMIFS handles them efficiently. The risk with bounded ranges is that data grows past row 5000 and the formula quietly ignores new rows. The risk with whole columns is that a total or note placed at the bottom of the sheet is added into your result.
A common fix is to store the ledger in an Excel table and refer to its columns by name. The ranges then grow with the data. If you stay with fixed ranges, add a check that compares the report with the source. This formula does that for a monthly roll-up row:
=ROUND(SUM(C10:N10) - SUM(Data!$F$2:$F$5000), 2)A result other than 0 means the roll-up missed some rows. The causes are usually a misspelled account, a date outside the report year, or text amounts. A later chapter builds this check into a full set of integrity tests.
Common mistakes
- Putting the criteria range before the sum range.
- Using ranges of different sizes.
- Forgetting the dollar signs, so the ranges slide down as you copy the formula.
- Typing a criterion such as
"Rent"directly in the formula, where it cannot be changed from the sheet. Point to a cell instead. - Assuming a result of 0 means the data is clean.
Summary
SUMIFS takes the column to add first, then any number of range-and-condition pairs. Rows must pass every pair to count. Keep the ranges the same size, anchor them with $, use mixed references for the criteria so one formula fills the grid, and reconcile the result to the source.
Exercise
A ledger has accounts in Data!B2:B5000, dates in Data!D2:D5000, and amounts in Data!F2:F5000. Write a SUMIFS formula that totals the amounts for the account named in $A8 where the date is on or after the date in B$2. Then say what the formula returns if the account name in $A8 is misspelled.
Show answer
=SUMIFS(Data!$F$2:$F$5000, Data!$B$2:$B$5000, $A8, Data!$D$2:$D$5000, ">="&B$2). The sum range F comes first, followed by the account pair and the date pair. If the account name is misspelled, no row matches and the formula returns 0, not an error, so you need a reconciliation check to notice the problem.
Exercise
A colleague's formula is =SUMIFS(Data!$B$2:$B$5000, Data!$F$2:$F$5000, $A5). It returns 0 for every account. What is wrong, and how do you fix it?
Show answer
The first argument is the account column, not the amount column, and the criteria pair points at the amounts. The sum range must come first and must be the amounts. The fix is =SUMIFS(Data!$F$2:$F$5000, Data!$B$2:$B$5000, $A5).