The Excel SUMIFS function applies several conditions at once and adds up only the rows that meet all of them. If you only have one condition, SUMIF is enough, but the two functions put the range to add in different positions, so it's easy to get them wrong when you copy a formula from one to the other.
Date ranges go in by joining an operator and a cell, as in ">="&cell, and if the result comes back as 0 or #VALUE!, start by checking your quotes and range sizes.
"Can you pull just this week's Google ad spend for me?" When you stack daily data for every channel in one sheet and build reports from it, you can get requests like this several times a day. You could filter and copy the total by hand, but if you have to rebuild the same table every week, it's much easier to put the conditions into a formula. In this post, let's walk through the difference between SUMIF and SUMIFS, formulas you can drop straight into an ad report, and the errors that come up most often.
1. What's the difference between SUMIF and SUMIFS?
The SUMIF function help article describes SUMIF as a function that adds the values in a range that meet a condition you specify, and it points you to SUMIFS for adding cells based on multiple criteria.
Put the syntax side by side and the difference is obvious. SUMIF is SUMIF(range, criteria, [sum_range]), with the condition first and the range to add last, while SUMIFS is SUMIFS(sum_range, criteria_range1, criteria1, ...), with the range to add at the very front.
| SUMIF | SUMIFS | |
|---|---|---|
| Number of conditions | 1 | Up to 127 range/criteria pairs |
| Position of the range to add | Third argument (optional) | First argument (required) |
| If you omit the range to add | Adds the values in the criteria range | Can't be omitted |
| If range sizes differ | Calculates without an error, but may add the wrong cells | #VALUE! error |
The SUMIFS function help article calls out this order difference too. It explains that sum_range is the first argument in SUMIFS but the third in SUMIF, which makes problems likely when you copy and edit similar formulas. If you take a SUMIF formula and just rename the function to SUMIFS to add another condition, the arguments end up in the wrong places, so it's safer to rewrite it in SUMIFS order from the start.
SUMIF goes "criteria range, criteria, range to add," and SUMIFS goes "range to add, criteria range 1, criteria 1, criteria range 2, criteria 2…" (figure labels in Korean).
You can use SUMIFS even with a single condition, so if a report is likely to gain more conditions later, standardizing on SUMIFS from the beginning is one way to go. So when you put several conditions into SUMIFS, how does Excel combine them?
2. How do you write a SUMIFS formula, and how are the conditions combined?
The example in the Sum values based on multiple conditions help article finds meat sales in the South region with =SUMIFS(D2:D11,A2:A11,"South",C2:C11,"Meat").
Column D holds the sales to add, column A with "South" is the first condition pair, and column C with "Meat" is the second. Only rows where the region is South and the type is Meat are picked, and adding column D for those rows gives 14719.
The key point is that every condition has to match for a row to be added. The Google Sheets SUMIFS help article states that a row must meet all criteria to be included in the sum, and Excel's COUNTIFS help article likewise says it counts the number of times all criteria are met. It helps to picture several sieves stacked on top of each other to sift sand. Only the grains that pass the first sieve drop into the second, and only the grains that make it through the last sieve land on the scale.
Each condition is one sieve. Only the ad spend of rows that pass every sieve goes into the total, so the more conditions you add, the fewer rows get added (figure labels in Korean).
You can put several kinds of values in the criteria slots. Pulling together the rules from the SUMIF and SUMIFS help articles:
- Text criteria: Wrap them in double quotes, like
"Google". The SUMIFS help article says that if you get 0, you should check whether your text criteria are wrapped in quotes. - Comparison criteria: Put the operator and the value together inside quotes, like
">160000". "Not equal to" is written as"<>Bananas". - Comparing with a cell value: As in the SUMIF help example
=SUMIF(A2:A5,">" & C2,B2:B5), join the quoted operator and the cell reference with&. - Wildcards:
?stands for any single character and*for any sequence of characters. To find an actual question mark or asterisk, put a tilde (~) in front of it.
So what do these rules look like once you put them into a real ad report?
3. Let's try SUMIFS in an ad report
Imagine you're the person who builds a weekly ad spend summary by channel. The source sheet has dates in column A, channel in column B, campaign in column C, and ad spend in column D, piling up day by day, and the report period goes in G1 (start date) and G2 (end date). All of the data in the example below is made up.
- Step 1, set up the summary table: Type "Google," "Meta," and "Naver" (Korea's largest search engine) in F5 through F7. The channel names must match column B of the source exactly, down to the last character.
- Step 2, write the first formula: In G5, enter
=SUMIFS($D$2:$D$7,$B$2:$B$7,F5,$A$2:$A$7,">="&$G$1,$A$2:$A$7,"<="&$G$2). This means: add the ad spend of rows where the channel matches F5 and the date is on or after the start date and on or before the end date. You use the same date column (column A) twice as a criteria range, once for the start of the period and once for the end. - Step 3, fill down: Drag G5 down to G7. Because the source ranges and period cells are locked with
$, they stay put, and only the channel cell changes to F6 and F7. The Switch between relative, absolute, and mixed references help article explains that you can toggle the$signs by selecting a reference in the formula bar and pressing F4. - Step 4, change only the period: Next week, just update the dates in G1 and G2 and the whole summary table recalculates.
Source: a sheet built with sample data in Microsoft Excel for Mac. With the period set to November 9–16, SUMIFS in G5 adds only the Google spend of 150,000 and 130,000 to return 280,000; G6 returns 90,000 and G7 returns 100,000 (screen in Korean: 구글 = Google, 메타 = Meta, 네이버 = Naver).
From the same source data, you can build a few more formulas just by changing the conditions.
| What you want | Example formula | Result with the sample data |
|---|---|---|
| Spend for campaigns with "Brand" in the name | =SUMIFS(D2:D7,C2:C7,"*Brand*") | 350,000 |
| Spend for every channel except Meta | =SUMIFS(D2:D7,B2:B7,"<>Meta") | 500,000 |
| Google campaigns whose names start with "Brand" | =SUMIFS(D2:D7,B2:B7,"Google",C2:C7,"Brand*") | 250,000 |
| Google or Meta spend | =SUMIFS(D2:D7,B2:B7,"Google")+SUMIFS(D2:D7,B2:B7,"Meta") | 570,000 |
Notice that the last row doesn't use a single SUMIFS for the "or" condition. As we saw earlier, SUMIFS conditions are a bundle that all have to be met, so if you set the channel condition to both Google and Meta at once, no row has both values and you get 0. That's why I added up a separate SUMIFS for each channel instead. But sometimes the formula looks right and the result still seems off. Where should you look first?
4. Why does SUMIFS return 0 or #VALUE!?
When SUMIFS returns something other than what you expected, the official help articles point to five main causes. Here they are by symptom.
| Symptom | Cause | Fix |
|---|---|---|
| Result is 0 | Text criteria aren't in quotes | Wrap them in double quotes, like "Google" |
| #VALUE! | The range to add and the criteria ranges have different numbers of rows and columns | Make every range the same size |
| #VALUE! | The formula refers to another workbook that's closed | Open that file and press F9 to recalculate |
| Wrong result | Criteria use a string longer than 255 characters | Shorten the string or split it and join with & |
| Total is larger than expected | The range to add contains TRUE/FALSE values | TRUE counts as 1 and FALSE as 0, so check the values |
The How to correct a #VALUE! error in the SUMIF/SUMIFS function help article uses =SUMIFS(C2:C10,A2:A12,A14,B2:B12,B14) as an example of the range-size problem and says to change the range to add to C2:C12.
The criteria ranges run to row 12 while the range to add stops at row 10, which causes the error. The same article says the #VALUE! you get from referring to a closed workbook goes away when you open that file and press F9 to refresh, so if your report pulls source data from another file, it's a good idea to keep that file open too.
One more thing to watch: SUMIF doesn't throw an error when range sizes differ. According to the SUMIF help article, when sum_range isn't the same size as the criteria range, Excel starts at the first cell of sum_range and adds a range the same size as the criteria range. For example, if the criteria range is A1:A5 and you enter B1:K5 as sum_range, the cells actually added are B1:B5. With no error showing, it's hard to notice whether the number is right, and the article also notes that performance may suffer in this case.
If none of the five causes in the table apply and your total is still off, it's worth suspecting that values that look like numbers are actually stored as text. The Convert numbers stored as text to numbers help article warns that such values can cause unexpected results, and if you see a green triangle warning in the top-left corner of a cell, I'd suggest checking how to convert numbers stored as text to numbers first.
5. SUMIFS, PivotTable, or COUNTIFS: which should you use?
SUMIFS isn't the only way to get totals by condition. Here's how I'd choose, split by the kind of work marketers do.
- SUMIFS when the report layout is fixed: For a report where you fill the same metrics into the same cells every week, SUMIFS fits well. You only need to change the period cells, and you can drop the numbers straight into a table layout on another sheet.
- A PivotTable when you're exploring different angles: If you need to switch often from channel to campaign to week, moving fields in a PivotTable is faster than editing formulas.
- COUNTIFS when you need a count: If you need the number of rows that match the conditions rather than a total, use COUNTIFS. The only difference is that there's no range to add, and the conditions are written the same way, so if you rename the SUMIFS formulas above to COUNTIFS and delete the first argument (the range to add), they count the rows that meet the same conditions.
- Same syntax in Google Sheets: Google Sheets SUMIFS also uses the order
SUMIFS(sum_range, criteria_range1, criterion1, ...), so you can carry the structure of your Excel formulas straight over.
If your source data grows downward every week, instead of fixing the range as D2:D7, you can turn the source into a table. With an Excel table and structured references, you can write formulas by column name, like =SUMIFS(Ads[Spend],Ads[Channel],"Google"), and you don't have to fix ranges when you paste in new rows.
If you keep editing ranges by hand every time rows are added, it's easy to run into the range-size error we saw earlier, so for a report you'll use for a long time, I'd suggest considering this approach as well.
Wrapping up
SUMIFS puts the range to add first, then lists criteria ranges and criteria in pairs, and if you remember that it only adds rows that meet every condition, you can handle most conditional sums. It's good to keep in mind that the argument order changes when you move over from SUMIF, and to get in the habit of checking quotes and range sizes first when the result looks odd. I also come back to the error table above whenever I get confused building report formulas. For the details of how each function behaves, please refer to the official help articles linked throughout this post.
FAQ
- What's the difference between SUMIF and SUMIFS?
- SUMIF takes only one condition, while SUMIFS takes up to 127 range/criteria pairs. The argument order is different too: in SUMIF the range to add is the third argument, and in SUMIFS it's the first. If you omit the range to add in SUMIF, it adds the values in the criteria range.
- How do I add a date range condition to SUMIFS?
- Use the same date column twice as a criteria range, and join the greater-than-or-equal operator with the start date cell, and the less-than-or-equal operator with the end date cell, each with an ampersand (&). Wrap the operators in double quotes and keep the cell references outside the quotes. Only rows that meet both conditions are added, so only values within the period go into the total.
- Why does SUMIFS return a #VALUE! error?
- The Microsoft help article points to two typical causes: the range to add and the criteria ranges have different numbers of rows and columns, or the formula refers to cells in another workbook that's closed. Make all ranges the same size, or open the referenced file and press F9 to recalculate.
- Can SUMIFS calculate an OR condition total?
- SUMIFS conditions are a bundle that all have to be met, so if you put two values on the same column as conditions at once, the result is 0. If you need the total for either of two values, such as Google or Meta, the simple approach is to calculate a separate SUMIFS for each value and add them.
Related posts
Posts that pair well with summarizing ad and order data in Excel:
- Excel PivotTable Guide: What It Is, How to Create and Refresh - How to view totals while switching criteria without formulas
- Excel Not Equal To (
<>) Operator: How to Use It in IF and COUNTIF - Where the quotes go when you add an exclusion to SUMIFS criteria - Excel Tables: Structured References vs. Regular Ranges - How to keep SUMIFS ranges from needing edits as rows grow