You use the SUMIF function to sum the values in a range that meet criteria that you specify. For example, suppose that in a column that contains numbers, you want to sum only the values that are larger than 5. You can use the following formula: =SUMIF(B2:B25,»>5″)
This video is part of a training course called Add numbers in Excel.
Tips:
-
If you want, you can apply the criteria to one range and sum the corresponding values in a different range. For example, the formula =SUMIF(B2:B5, «John», C2:C5) sums only the values in the range C2:C5, where the corresponding cells in the range B2:B5 equal «John.»
-
To sum cells based on multiple criteria, see SUMIFS function.
Important: The SUMIF function returns incorrect results when you use it to match strings longer than 255 characters or to the string #VALUE!.
Syntax
SUMIF(range, criteria, [sum_range])
The SUMIF function syntax has the following arguments:
-
range Required. The range of cells that you want evaluated by criteria. Cells in each range must be numbers or names, arrays, or references that contain numbers. Blank and text values are ignored. The selected range may contain dates in standard Excel format (examples below).
-
criteria Required. The criteria in the form of a number, expression, a cell reference, text, or a function that defines which cells will be added. Wildcard characters can be included — a question mark (?) to match any single character, an asterisk (*) to match any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) preceding the character.
For example, criteria can be expressed as 32, «>32», B5, «3?», «apple*», «*~?», or TODAY().
Important: Any text criteria or any criteria that includes logical or mathematical symbols must be enclosed in double quotation marks («). If the criteria is numeric, double quotation marks are not required.
-
sum_range Optional. The actual cells to add, if you want to add cells other than those specified in the range argument. If the sum_range argument is omitted, Excel adds the cells that are specified in the range argument (the same cells to which the criteria is applied).
Sum_range
should be the same size and shape as range. If it isn’t, performance may suffer, and the formula will sum a range of cells that starts with the first cell in sum_range but has the same dimensions as range. For example:
range
sum_range
Actual summed cells
A1:A5
B1:B5
B1:B5
A1:A5
B1:K5
B1:B5
Examples
Example 1
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.
Property Value |
Commission |
Data |
---|---|---|
$100,000 |
$7,000 |
$250,000 |
$200,000 |
$14,000 |
|
$300,000 |
$21,000 |
|
$400,000 |
$28,000 |
|
Formula |
Description |
Result |
=SUMIF(A2:A5,»>160000″,B2:B5) |
Sum of the commissions for property values over $160,000. |
$63,000 |
=SUMIF(A2:A5,»>160000″) |
Sum of the property values over $160,000. |
$900,000 |
=SUMIF(A2:A5,300000,B2:B5) |
Sum of the commissions for property values equal to $300,000. |
$21,000 |
=SUMIF(A2:A5,»>» & C2,B2:B5) |
Sum of the commissions for property values greater than the value in C2. |
$49,000 |
Example 2
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.
Category |
Food |
Sales |
---|---|---|
Vegetables |
Tomatoes |
$2,300 |
Vegetables |
Celery |
$5,500 |
Fruits |
Oranges |
$800 |
Butter |
$400 |
|
Vegetables |
Carrots |
$4,200 |
Fruits |
Apples |
$1,200 |
Formula |
Description |
Result |
=SUMIF(A2:A7,»Fruits»,C2:C7) |
Sum of the sales of all foods in the «Fruits» category. |
$2,000 |
=SUMIF(A2:A7,»Vegetables»,C2:C7) |
Sum of the sales of all foods in the «Vegetables» category. |
$12,000 |
=SUMIF(B2:B7,»*es»,C2:C7) |
Sum of the sales of all foods that end in «es» (Tomatoes, Oranges, and Apples). |
$4,300 |
=SUMIF(A2:A7,»»,C2:C7) |
Sum of the sales of all foods that do not have a category specified. |
$400 |
Top of Page
Need more help?
See also
SUMIFS function
COUNTIF function
Sum values based on multiple conditions
How to avoid broken formulas
VLOOKUP function
На чтение 2 мин
Функция СУММЕСЛИ (SUMIF) в Excel используется для суммирования значений, отвечающих заданным вами критериям.
Содержание
- Что возвращает функция
- Синтаксис
- Аргументы функции
- Дополнительная информация
- Примеры использования функции СУММЕСЛИ в Excel
Что возвращает функция
Возвращает сумму чисел, указанных в качестве аргументов и отвечающих заданным в формуле критериям.
Больше лайфхаков в нашем Telegram Подписаться
Синтаксис
=SUMIF(range, criteria [sum_range]) — английская версия
=СУММЕСЛИ(диапазон; условие; [диапазон_суммирования]) — русская версия
Аргументы функции
- range (диапазон) — диапазон ячеек, по которым оцениваются критерии. Аргументом могут быть числа, текст, массивы или ссылки, содержащие числа;
- criteria (условие) — критерии, которые проверяются по указанному диапазону ячеек и определяют, какие ячейки суммировать;
- sum_range (диапазон_суммирования) — (не обязательно) суммируемые ячейки. Если этот аргумент не указан, то функция использует аргумент range (диапазон) в качестве sum_range (диапазон_суммирования).
Дополнительная информация
- суммирование ячеек в функции СУММЕСЛИ производится на основе одного критерия, если вам необходимо указать несколько критериев — используйте функцию SUMIFS (СУММЕСЛИМН);
- пустые и текстовые ячейки в аргументе sum_range (диапазон_суммирования) игнорируются;
- критерием для функции могут служить числа, выражения, результаты вычисления из других ячеек, текст или формула;
- если в качестве критерия указан текст или математический/логический символ (=,+,-,/,*), то такие значения должны быть указаны в двойных кавычках;
- аргумент с критерием не должен быть длиннее чем 255 символов;
- в качестве критерия могут использоваться подстановочные знаки (*);
- если количество ячеек в диапазоне критерия и аргументе sum_range (диапазон_суммирования) различаются, то размер диапазона критерия будет в приоритете.
Примеры использования функции СУММЕСЛИ в Excel
The SUMIF function sums cells in a range that meet a single condition, referred to as criteria. The SUMIF function is a common, widely used function in Excel, and can be used to sum cells based on dates, text values, and numbers. Note that SUMIF can only apply one condition. To sum cells using multiple criteria, see the SUMIFS function.
Syntax
The generic syntax for SUMIF looks like this:
=SUMIF(range,criteria,[sum_range])
The SUMIF function takes three arguments. The first argument, range, is the range of cells to apply criteria to. The second argument, criteria, is the criteria to apply, along with any logical operators. The last argument, sum_range, is the range that should be summed. Note that sum_range is optional. If sum_range is not provided, SUMIF will sum cells in the first argument, range.
Examples: Basic Usage | Criteria in another cell | Not equal to | Blank cells | Dates | Wildcards | Videos
Applying criteria
The SUMIF function supports logical operators (>,<,<>,=) and wildcards (*,?) for partial matching. The tricky part about using the SUMIF function is the syntax needed to apply criteria. This is because SUMIF is in a group of eight functions that split logical criteria into two parts, range and criteria. Because of this design, operators need to be enclosed in double quotes («»). The table below shows examples of the syntax needed for common criteria:
Target | Criteria |
---|---|
Cells greater than 75 | «>75» |
Cells equal to 100 | 100 or «100» |
Cells less than or equal to 100 | «<=100» |
Cells equal to «Red» | «red» |
Cells not equal to «Red» | «<>red» |
Cells that are blank «» | «» |
Cells that are not blank | «<>» |
Cells that begin with «X» | «x*» |
Cells less than A1 | «<«&A1 |
Cells less than today | «<«&TODAY() |
Notice the last two examples involve concatenation with the ampersand (&) character. Any time you are using a value from another cell, or using the result of a formula in criteria with a logical operator like «<«, you will need to concatenate. This is because Excel needs to evaluate cell references and formulas to get a value before that value can be joined with an operator.
Limitations
There are a couple of limitations with SUMIF that you should be aware of. First, SUMIF only supports a single condition. If you need to sum cells using multiple criteria, use the SUMIFS function. Second, the SUMIF function requires an actual range for the range argument; you can’t substitute an array. This means you can’t do things like extract the year from a range that contains dates inside the SUMIF function. If you need to manipulate values that appear in the argument before applying criteria, the SUMPRODUCT function is a flexible solution.
Basic usage
With numbers in the range A1:A10, you can use SUMIF to sum cells greater than 5 like this:
=SUMIF(A1:A10,">5")
If the range B1:B10 contains color names like «red», «blue», and «green», you can use SUMIF to sum numbers in A1:A10 when the color in B1:B10 is «red» like this:
=SUMIF(B1:B10,"red",A1:A10)
Notice A1:A10 is now entered as the sum_range, because it is different from range, which contains only color names. To recap: criteria is applied to cells in range. When cells in range meet criteria, corresponding cells in sum_range are summed. The sum_range argument is optional. If sum_range is omitted, the cells in range are summed instead.
Worksheet example
In the worksheet shown, there are three SUMIF formulas. In the first formula (G5), SUMIF returns total Sales where Name = «jim». In the second formula (G6), SUMIF returns total Sales where State = «ca» (California). In the third formula (G7), SUMIF returns the total of Sales > 100:
=SUMIF(B5:B15,"jim",D5:D15) // name = "jim"
=SUMIF(C5:C15,"ca",D5:D15) // state = "ca"
=SUMIF(D5:D15,">100") // sales > 100
Notice the equals sign (=) is not required when constructing «is equal to» criteria. Also notice SUMIF is not case-sensitive; you can use «jim» or «Jim». Finally, notice that the last formula does not include sum_range, so range is summed instead.
Criteria in another cell
A value from another cell can be included in criteria using concatenation. In the example below, SUMIF will return the sum of all sales over the value in G4. Notice the greater than operator (>), which is text, must be enclosed in quotes. The formula in G5 is:
=SUMIF(D5:D9,">"&G4) // sum if greater than G4
Not equal to
To express «not equal to» criteria, use the «<>» operator surrounded by double quotes («»):
=SUMIF(B5:B9,"<>red",C5:C9) // not equal to "red"
=SUMIF(B5:B9,"<>blue",C5:C9) // not equal to "blue"
=SUMIF(B5:B9,"<>"&E7,C5:C9) // not equal to E7
Again notice SUMIF is not case-sensitive.
Blank cells
SUMIF can calculate sums based on cells that are blank or not blank. In the example below, SUMIF is used to sum the amounts in column C depending on whether column D contains «x» or is empty:
=SUMIF(D5:D9,"",C5:C9) // blank
=SUMIF(D5:D9,"<>",C5:C9) // not blank
Dates
The best way to use SUMIF with dates is to refer to a valid date in another cell, or use the DATE function. The example below shows both methods:
=SUMIF(B5:B9,"<"&DATE(2019,3,1),C5:C9)
=SUMIF(B5:B9,">="&DATE(2019,4,1),C5:C9)
=SUMIF(B5:B9,">"&E9,C5:C9)
Notice we must concatenate an operator to the date in E9. To use more advanced date criteria (i.e. all dates in a given month, or all dates between two dates) you’ll want to switch to the SUMIFS function, which can handle multiple criteria.
Wildcards
The SUMIF function supports wildcards, as seen in the example below:
=SUMIF(B5:B9,"mi*",C5:C9) // begins with "mi"
=SUMIF(B5:B9,"*ota",C5:C9) // ends with "ota"
=SUMIF(B5:B9,"????",C5:C9) // contains 4 characters
The tilde (~) is an escape character to allow you to find literal wildcards. For example, to match a literal question mark (?), asterisk(*), or tilde (~), add a tilde in front of the wildcard (i.e. ~?, ~*, ~~).
Average range caution
SUMIF makes certain assumptions about the size of sum_range, essentially resizing it when necessary to match the range argument, using the upper left cell in the range as an origin. In some cases, this behavior can create a result that seems reasonable but is in fact incorrect. For an example of this problem, see this article.
Notes
- SUMIF only supports one condition. Use the SUMIFS function for multiple criteria.
- When sum_range is omitted, the cells in range will be summed.
- Non-numeric criteria must be enclosed in double quotes (i.e. «<100», «>32», «TX»)
- Cell references in criteria are not enclosed in quotes, i.e. «<«&A1
- The wildcard characters ? and * can be used in criteria. A question mark matches any one character and an asterisk matches any sequence of characters (zero or more).
- To match a literal question mark(?) or asterisk (*), use a tilde (~) like (~?, ~*).
- SUMIF requires a range, you can’t substitute an array.
Содержание
- Функция СУММЕСЛИ
- Синтаксис
- SUMIF function
- Syntax
- Sum values based on multiple conditions
- Give it a try
- SUMIFS function
- Syntax
- Examples
- Common Problems
- Best practices
- Need more help?
- SUMIF Function
- Related functions
- Summary
- Purpose
- Return value
- Arguments
- Syntax
- Usage notes
- Syntax
- Applying criteria
- Criteria in another cell
- Not equal to
- Blank cells
- Dates
- Wildcards
- Average range caution
Функция СУММЕСЛИ
Функция СУММЕСЛИ используется, если необходимо просуммировать значения диапазон, соответствующие указанному критерию. Предположим, например, что в столбце с числами необходимо просуммировать только значения, превышающие 5. Для этого можно использовать следующую формулу: =СУММЕСЛИ(B2:B25;»> 5″)
Это видео — часть учебного курса Сложение чисел в Excel.
При необходимости условия можно применить к одному диапазону, а просуммировать соответствующие значения из другого диапазона. Например, формула =СУММЕСЛИ(B2:B5; «Иван»; C2:C5) суммирует только те значения из диапазона C2:C5, для которых соответствующие значения из диапазона B2:B5 равны «Иван».
Если необходимо выполнить суммирование ячеек в соответствии с несколькими условиями, используйте функцию СУММЕСЛИМН.
Важно: Функция СУММЕСЛИ возвращает неверные результаты при использовании для сопоставления строк длиной более 255 символов или строкового #VALUE!.
Синтаксис
СУММЕСЛИ(диапазон; условие; [диапазон_суммирования])
Аргументы функции СУММЕСЛИ описаны ниже.
Диапазон — обязательный аргумент. Диапазон ячеек, оцениваемых на соответствие условиям. Ячейки в каждом диапазоне должны содержать числа, имена, массивы или ссылки на числа. Пустые и текстовые значения игнорируются. Выбранный диапазон может содержать даты в стандартном формате Excel (см. примеры ниже).
Условие .Обязательный аргумент. Условие в форме числа, выражения, ссылки на ячейку, текста или функции, определяющее, какие ячейки необходимо суммировать. Можно включить подстановочные знаки: вопросительный знак (?) для сопоставления с любым одним символом, звездочка (*) для сопоставления любой последовательности символов. Если требуется найти непосредственно вопросительный знак (или звездочку), необходимо поставить перед ним знак «тильда» (
Например, критерии можно выразить как 32, «>32», B5, «3?», «apple*», «*
Важно: Все текстовые условия и условия с логическими и математическими знаками необходимо заключать в двойные кавычки ( «). Если условием является число, использовать кавычки не требуется.
Диапазон_суммирования .Необязательный аргумент. Ячейки, значения из которых суммируются, если они отличаются от ячеек, указанных в качестве диапазона. Если аргумент диапазон_суммирования опущен, Excel суммирует ячейки, указанные в аргументе диапазон (те же ячейки, к которым применяется условие).
Sum_range должны иметь тот же размер и форму, что и диапазон. Если это не так, производительность может снизиться, и формула суммирует диапазон ячеек, который начинается с первой ячейки в sum_range но имеет те же размеры, что и диапазон. Например:
Источник
SUMIF function
You use the SUMIF function to sum the values in a range that meet criteria that you specify. For example, suppose that in a column that contains numbers, you want to sum only the values that are larger than 5. You can use the following formula: =SUMIF(B2:B25,»>5″)
This video is part of a training course called Add numbers in Excel.
If you want, you can apply the criteria to one range and sum the corresponding values in a different range. For example, the formula =SUMIF(B2:B5, «John», C2:C5) sums only the values in the range C2:C5, where the corresponding cells in the range B2:B5 equal «John.»
To sum cells based on multiple criteria, see SUMIFS function.
Important: The SUMIF function returns incorrect results when you use it to match strings longer than 255 characters or to the string #VALUE!.
Syntax
SUMIF(range, criteria, [sum_range])
The SUMIF function syntax has the following arguments:
range Required. The range of cells that you want evaluated by criteria. Cells in each range must be numbers or names, arrays, or references that contain numbers. Blank and text values are ignored. The selected range may contain dates in standard Excel format (examples below).
criteria Required. The criteria in the form of a number, expression, a cell reference, text, or a function that defines which cells will be added. Wildcard characters can be included — a question mark (?) to match any single character, an asterisk (*) to match any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (
) preceding the character.
For example, criteria can be expressed as 32, «>32», B5, «3?», «apple*», «*
Important: Any text criteria or any criteria that includes logical or mathematical symbols must be enclosed in double quotation marks ( «). If the criteria is numeric, double quotation marks are not required.
sum_range Optional. The actual cells to add, if you want to add cells other than those specified in the range argument. If the sum_range argument is omitted, Excel adds the cells that are specified in the range argument (the same cells to which the criteria is applied).
Sum_range should be the same size and shape as range. If it isn’t, performance may suffer, and the formula will sum a range of cells that starts with the first cell in sum_range but has the same dimensions as range. For example:
Источник
Sum values based on multiple conditions
Let’s say that you need to sum values with more than one condition, such as the sum of product sales in a specific region. This is a good case for using the SUMIFS function in a formula.
Have a look at this example in which we have two conditions: we want the sum of Meat sales (from column C) in the South region (from column A).
Here’s a formula you can use to acomplish this:
The result is the value 14,719.
Let’s look more closely at each part of the formula.
=SUMIFS is an arithmetic formula. It calculates numbers, which in this case are in column D. The first step is to specify the location of the numbers:
In other words, you want the formula to sum numbers in that column if they meet the conditions. That cell range is the first argument in this formula—the first piece of data that the function requires as input.
Next, you want to find data that meets two conditions, so you enter your first condition by specifying for the function the location of the data (A2:A11) and also what the condition is—which is “South”. Notice the commas between the separate arguments:
Quotation marks around “South” specify that this text data.
Finally, you enter the arguments for your second condition – the range of cells (C2:C11) that contains the word “meat,” plus the word itself (surrounded by quotes) so that Excel can match it. End the formula with a closing parenthesis ) and then press Enter. The result, again, is 14,719.
As you type the SUMIFS function in Excel, if you don’t remember the arguments, help is ready at hand. After you type =SUMIFS(, Formula AutoComplete appears beneath the formula, with the list of arguments in their proper order.
Looking at the image of Formula AutoComplete and the list of arguments, in our example sum_rangeis D2:D11, the column of numbers you want to sum; criteria_range1is A2.A11, the column of data where criteria1 “South” resides.
As you type, the rest of the arguments will appear in Formula AutoComplete (not shown here); criteria_range2 is C2:C11, the column of data where criteria2 “Meat” resides.
If you click SUMIFS in Formula AutoComplete, an article opens to give you more help.
Give it a try
If you want to experiment with the SUMIFS function, here’s some sample data and a formula that uses the function.
You can work with sample data and formulas right here, in this Excel for the web workbook. Change values and formulas, or add your own values and formulas and watch the results change, live.
Copy all the cells in the table below, and paste into cell A1 in a new worksheet in Excel. You may want to adjust column widths to see the formulas better
Источник
SUMIFS function
The SUMIFS function, one of the math and trig functions, adds all of its arguments that meet multiple criteria. For example, you would use SUMIFS to sum the number of retailers in the country who (1) reside in a single zip code and (2) whose profits exceed a specific dollar value.
Syntax
SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], . )
The range of cells to sum.
The range that is tested using Criteria1.
Criteria_range1 and Criteria1 set up a search pair whereby a range is searched for specific criteria. Once items in the range are found, their corresponding values in Sum_range are added.
The criteria that defines which cells in Criteria_range1 will be added. For example, criteria can be entered as 32, «>32», B4, «apples», or «32».
Criteria_range2, criteria2, … (optional)
Additional ranges and their associated criteria. You can enter up to 127 range/criteria pairs.
Examples
To use these examples in Excel, drag to select the data in the table, right-click the selection, and pick Copy. In a new worksheet, right-click cell A1 and pick Match Destination Formatting under Paste Options.
=SUMIFS(A2:A9, B2:B9, «=A*», C2:C9, «Tom»)
Adds the number of products that begin with A and were sold by Tom. It uses the wildcard character * in Criteria1, «=A*» to look for matching product names in Criteria_range1 B2:B9, and looks for the name «Tom» in Criteria_range2 C2:C9. It then adds the numbers in Sum_range A2:A9 that meet both conditions. The result is 20.
=SUMIFS(A2:A9, B2:B9, «<>Bananas», C2:C9, «Tom»)
Adds the number of products that aren’t bananas and are sold by Tom. It excludes bananas by using <> in the Criteria1, «<>Bananas», and looks for the name «Tom» in Criteria_range2 C2:C9. It then adds the numbers in Sum_range A2:A9 that meet both conditions. The result is 30.
Common Problems
0 (Zero) is shown instead of the expected result.
Make sure Criteria1,2 are in quotation marks if you are testing for text values, like a person’s name.
The result is incorrect when Sum_range has TRUE or FALSE values.
TRUE and FALSE values for Sum_range are evaluated differently, which may cause unexpected results when they’re added.
Cells in Sum_range that contain TRUE evaluate to 1. Those that contain FALSE evaluate to 0 (zero).
Best practices
Use wildcard characters.
Using wildcard characters like the question mark (?) and asterisk (*) in criteria1,2 can help you find matches that are similar but not exact.
A question mark matches any single character. An asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (
) in front of the question mark.
For example, =SUMIFS(A2:A9, B2:B9, «=A*», C2:C9, «To?») will add all instances with name that begin with «To» and ends with a last letter that could vary.
Understand the difference between SUMIF and SUMIFS.
The order of arguments differ between SUMIFS and SUMIF. In particular, the sum_range argument is the first argument in SUMIFS, but it is the third argument in SUMIF. This is a common source of problems using these functions.
If you’re copying and editing these similar functions, make sure you put the arguments in the correct order.
Use the same number of rows and columns for range arguments.
The Criteria_range argument must contain the same number of rows and columns as the Sum_range argument.
Need more help?
You can always ask an expert in the Excel Tech Community or get support in the Answers community.
Источник
SUMIF Function
Summary
The Excel SUMIF function returns the sum of cells that meet a single condition. Criteria can be applied to dates, numbers, and text. The SUMIF function supports logical operators (>, ,=) and wildcards (*,?) for partial matching.
Purpose
Return value
Arguments
- range — Range to apply criteria to.
- criteria — Criteria to apply.
- sum_range — [optional] Range to sum. If omitted, cells in range are summed.
Syntax
Usage notes
The SUMIF function sums cells in a range that meet a single condition, referred to as criteria. The SUMIF function is a common, widely used function in Excel, and can be used to sum cells based on dates, text values, and numbers. Note that SUMIF can only apply one condition. To sum cells using multiple criteria, see the SUMIFS function.
Syntax
The generic syntax for SUMIF looks like this:
The SUMIF function takes three arguments. The first argument, range, is the range of cells to apply criteria to. The second argument, criteria, is the criteria to apply, along with any logical operators. The last argument, sum_range, is the range that should be summed. Note that sum_range is optional. If sum_range is not provided, SUMIF will sum cells in the first argument, range.
Applying criteria
The SUMIF function supports logical operators (>, ,=) and wildcards (*,?) for partial matching. The tricky part about using the SUMIF function is the syntax needed to apply criteria. This is because SUMIF is in a group of eight functions that split logical criteria into two parts, range and criteria. Because of this design, operators need to be enclosed in double quotes («»). The table below shows examples of the syntax needed for common criteria:
Target | Criteria |
---|---|
Cells greater than 75 | «>75» |
Cells equal to 100 | 100 or «100» |
Cells less than or equal to 100 | » red» |
Cells that are blank «» | «» |
Cells that are not blank | «<>« |
Cells that begin with «X» | «x*» |
Cells less than A1 | » 100:
Notice the equals sign (=) is not required when constructing «is equal to» criteria. Also notice SUMIF is not case-sensitive; you can use «jim» or «Jim». Finally, notice that the last formula does not include sum_range, so range is summed instead. Criteria in another cellA value from another cell can be included in criteria using concatenation. In the example below, SUMIF will return the sum of all sales over the value in G4. Notice the greater than operator (>), which is text, must be enclosed in quotes. The formula in G5 is: Not equal toTo express «not equal to» criteria, use the «<>» operator surrounded by double quotes («»): Again notice SUMIF is not case-sensitive. Blank cellsSUMIF can calculate sums based on cells that are blank or not blank. In the example below, SUMIF is used to sum the amounts in column C depending on whether column D contains «x» or is empty: DatesThe best way to use SUMIF with dates is to refer to a valid date in another cell, or use the DATE function. The example below shows both methods: Notice we must concatenate an operator to the date in E9. To use more advanced date criteria (i.e. all dates in a given month, or all dates between two dates) you’ll want to switch to the SUMIFS function, which can handle multiple criteria. WildcardsThe SUMIF function supports wildcards, as seen in the example below: ) is an escape character to allow you to find literal wildcards. For example, to match a literal question mark (?), asterisk(*), or tilde ( ), add a tilde in front of the wildcard (i.e. Average range cautionSUMIF makes certain assumptions about the size of sum_range, essentially resizing it when necessary to match the range argument, using the upper left cell in the range as an origin. In some cases, this behavior can create a result that seems reasonable but is in fact incorrect. For an example of this problem, see this article. Источник Adblock |
Adding up all the numbers in a single column or row in Excel is easy — the SUM function will work just fine. But what if you only want to sum cells that meet a certain condition – for example, to calculate the total sales generated by a specific product? In this case, Excel has a useful function called SUMIF to help you with the job!
Now, let’s go over what the SUMIF function is and how to use it with various examples, so you can see just how helpful this tool can be!
What is the SUMIF function in Excel?
The SUMIF function is a perfect choice when you’re looking for an easy way to aggregate certain data quickly. Unlike pivot tables, which may require more advanced knowledge in order to use correctly, SUMIF is relatively easy to get started with.
Here we have a spreadsheet that shows how much revenue was generated by each product and its packaging:
As you’re looking at the above data, the following questions might cross your mind:
- What is the total revenue generated by Bali Arabica?
- What is the total revenue generated from products with prices under $50?
- What is the total revenue generated from products packaged in paper bags?
The SUMIF function can help you answer those questions quickly. With it, you can sum values based on a single criteria, like those specified by the above questions.
Can I use SUMIF with multiple criteria?
SUMIF does not support multiple criteria. For example, you can’t use it to answer questions like: “What is the total revenue generated by products with paper bag packaging AND prices under $50?“. To work around this limitation, you’ll need to use the SUMIFS function, which is the more advanced version of SUMIF.
So, while SUMIF in Excel is powerful and easy to use, it does have its limitations. For that reason, you will find several examples in this article using SUMIFS as well as other functions as a workaround for solving cases that cannot be solved using SUMIF.
Excel SUMIF syntax and parameters
Syntax
=SUMIF(critera_range, criteria, [sum_range])
Parameters or arguments
Parameters | Description |
---|---|
criteria_range |
Required. The range of cells that contains the criteria. |
criteria |
Required. The criteria used to determine which cells to add. It can be in the form of a number, expression, cell reference, text, or function.
Note: You need to use double quotation marks around any text criteria that include logical or mathematical symbols. If the criteria are numeric, you don’t need double quotes. You can also use logical operators as well as wildcards for partial matching, which makes the function powerful. Wildcards: – An asterisk ( – A tilde ( |
[sum_range] |
Optional. The range of cells to add. If you don’t specify this argument, Excel adds the cells that are specified in the criteria_range argument. |
How to use SUMIF in Excel: Basic usage
To have a good understanding of how to use the SUMIF function in Excel, let’s take a look at an example below. Suppose you want to find the total revenue generated by Bali Arabica, and want to store the result in G3.
To do that, follow the steps below:
Step 1: Position your cursor on G3 and start entering the formula.
=SUMIF(
Step 2: Enter the range of cells that contains the criteria, which is A2:A9
.
=SUMIF(A2:A9
Step 3: Set your criteria in the second argument by typing "Bali Arabica"
.
=SUMIF(A2:A9,"Bali Arabica"
Note: You can type
"bali arabica"
or"BALI ARABICA"
because SUMIF is not case-sensitive. You can also add the “=
” operator in the criteria ("=Bali Arabica"
), but the equal sign (=
) is not necessarily required when creating the “is equal to” criteria.
Step 4: Select a range of cells that you want to sum, which is D2:D9
. After that, close the parentheses and press Enter.
=SUMIF(A2:A9,"Bali Arabica", D2:D9)
Let’s see what exactly happened:
- Excel searched for the word “Bali Arabica” in the range A2:A9
- If any row had that word, Excel added the revenue value in column D of the same row.
- In the end, you get the sum of all revenue for Bali Arabica.
Note: If your spreadsheet has many rows, using this formula that refers to the entire column may be more convenient:
=SUMIF(A:A,"Bali Arabica",D:D)
Now, if you’d like, try to calculate the revenue generated from Dark Sumatra, Italian Espresso, and Super Dark Espresso. You can follow the same steps as above (Step 1-4).
Alternatively, you can insert the SUMIF formula from the ribbon menu. To do that, click Formula, and then in the Function Library section, click Math & Trig. Look for the SUMIF function in the list and select it.
A popup will appear, allowing you to enter the function arguments. See the following arguments for Dark Sumatra. When done, click the OK button.
Excel SUMIF vs. SUMIFS
When talking about SUMIF, we really must also discuss SUMIFS. Both functions allow you to sum data based on certain conditions. The difference? SUMIF only supports a single criteria, whereas SUMIFS can handle multiple criteria.
SUMIFS syntax
=SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], …)
The syntax is different from SUMIF in that you need to include the sum_range
argument before any other arguments. Also, sum_range
is a required argument, not optional like in the SUMIF function. Following the sum_range
argument is the pair of the first criteria range and criteria (criteria_range1
and criteria1
), and this pair of parameters is also required.
You can use SUMIFS even for one criteria (like SUMIF). You can add as many criteria as necessary, up to the limit of 127 pairs.
The basics of how to use these parameters are the same as SUMIF, so we won’t repeat the same explanation here. That means you won’t have to read a longer 😉
How to use SUMIF in Excel if your data is from different sources
Have you ever wanted to analyze data using Microsoft Excel, but your data is stored in external sources such as Jira, PipeDrive, Shopify, etc.? If yes, but you just couldn’t figure out how, our integration tool, Coupler.io, can help you. With this tool, you can import and combine data from different sources into Excel without coding. You can even automate the process on a schedule!
It’s important to note that your destination file needs to be an Excel Online file on OneDrive. If you want to use a file shared by another user, ensure you have edit access to the file.
To start using Coupler.io, sign up to it (it’s easy and no credit card is required). Then, all you need to do is create a new importer. A wizard will help you configure these three details:
- Source — You can take data from Airtable, Xero, Slack, Trello, and more.
- Destination — Select Microsoft Excel.
- Schedule— If you’d like, you can set up automatic data refresh on a schedule: hourly, daily, or monthly.
Pretty easy, right?! Once you finish setting up the importer and run it, your Excel file will be updated. Check out the available Excel integrations.
After that, you can start analyzing your data using Excel. 🙂
Common examples of how to use the SUMIF function in Excel
Understanding the basic use of SUMIF is one thing. But it’s better to be aware that there are many different ways to use this function. Now, let’s look at some common examples so we can get an idea of other fun things we can do with this function.
#1: Excel SUMIF if cells are equal to a value in another cell
With the data below, suppose you want to find out how many items were sold at $200. You can use this formula:
=SUMIF(B2:B9,200,C2:C9)
But instead of typing 200 manually as the second parameter, you can just refer to E3, as shown in the following formula:
=SUMIF(B2:B9,E3,C2:C9)
#2: If cells are not equal to
To calculate using the “not equal to” criteria, use the “<>
” operator (with double quotes).
Now, assume that you want to calculate the total sales generated by products other than Rose in E3 and other than Daisy in E4. Use the following formulas:
- Not equal to Rose (E4):
=SUMIF(A2:A6,"<>Rose",B2:B6)
- Not equal to Daisy (E5):
=SUMIF(A2:A6,"<>"&D4,B2:B6)
Notice that for Daisy, we use a cell reference in the formula.
#3: If cells are less than / less than or equal to a number
Use the “<
” operator to mean “less than” and “<=
” to mean “less than or equal to“. The following example calculates the quantities of flowers with prices per stem that are:
- Less than $0.45 (F5):
=SUMIF(B2:B9,"<0.45",C2:C9)
- Less than or equal to $0.45 (F6):
=SUMIF(B2:B9,"<=0.45",C2:C9)
#4: If cell contains text
To sum if cells contain a specific text, you need to use a wildcard when specifying the criteria in the SUMIF function.
The following example calculates the total quantities of flowers with names containing “white“. Notice again that SUMIF is not case-sensitive. The formula in F5:
=SUMIF(A2:A9,"*white*",C2:C9)
#5: Excel SUMIF if cells contain an asterisk
Asterisks themselves are wildcards. So, to find text that contains an asterisk, you’ll need to use a tilde (~
) to treat the character literally (not as a wildcard). The following example shows how to sum the amount for items that:
- Contain * (F5):
=SUMIF(B2:B9, "*~**", C2:C9)
- Contain * at the end (F6):
=SUMIF(B2:B9,"*~*",C2:C9)
#6: Excel SUMIF to sum values based on cells that are blank
Use double quotes without any space in between (""
) in the criteria if you want to sum based on cells that are blank. Blank means empty or zero character length.
For the following spreadsheet, suppose you want to calculate the total bill for works that are still ongoing (not finished yet). To do that, you calculate the sum based on the finish dates that are blank using the following formula:
=SUMIF(C2:C11,"", D2:D11)
#7: Excel SUMIF to sum values based on cells that are not blank
Use the “not equal to” operator enclosed with double quotes (“<>
“) in the criteria if you want to sum based on cells that are not blank.
Now, suppose you want to calculate the total bill only for works that are done (finish dates are not empty), use the following formula:
=SUMIF(C2:C11,"<>",D2:D11)
#8: If date is greater than, greater than or equal to
Use the “>
” operator for greater than and “>=
” for greater than or equal to. The following example sums the total bill for works that started:
- After Jun 5, 2021 (F5):
=SUMIF(B2:B11,">6/5/2021",C2:C11)
- On or after Jun 5, 2021 (F6):
=SUMIF(B2:B11,">="&DATE(2021,6,5),C2:C11)
Notice the formula in F6. You can also use the DATE function in the criteria.
Check out our guide dedicated to Excel SUMIF with Date Criteria.
#9: Excel SUMIF to sum values with the time format
Excel time values are actually numbers and you can sum them up using the SUMIF function like other numeric values. All you need to do is ensure that your data is in the correct time format. But how to set the correct time format? Well, it’s easy. Here’s an example:
Suppose you want to format Duration (column C) so that it uses the “h:mm:ss
” format as shown in the following screenshot:
Follow the simple steps below:
Step 1: Select the entire column C (or only C2:C14 if you want to select this range only).
Step 2: Right-click and select Format Cells.
Step 3: Click Custom in the category list, then select h:mm:ss on the right.
Step 4: Click OK.
Now, let’s say you want to sum the total duration for Specialization 2. You can use the following formula:
=SUMIF(A2:A14,E4,C2:C14)
Note: When the sum of time can be greater than 24 hours, you should format the result cells to [h]:mm:ss to avoid the wrong total hours displayed in the results. That’s because for the normal time format like “h:mm:ss”, hours will reset to zero every 24 hours.
#10: With multiple OR criteria
To sum numbers based on other cells being equal to either one value or another, one of the solutions is by using multiple SUMIF functions in one formula.
With the following table, suppose you want to sum the quantity sold for either Orchid OR Sunflower. To do that, you can use the following formula:
=SUMIF(B2:B9,"Orchid",C2:C9)+SUMIF(B2:B9,"Sunflower",C2:C9)
The solution here is very simple, and when there are only a few criteria, it often gets the job done quickly. However, if you want to sum values with more than three OR conditions (let’s say), then the formula will become long and complex. To avoid this problem, check out example #11 below, which uses a more advanced method that does not require adding up all of those different parts separately in order to get your total value.
Advanced examples of how to use the SUMIF function in Excel + without Excel SUMIF
Here are some more examples you may find helpful when summing values with criteria.
#11: Excel SUMIF with an array as the criteria argument
With the following data, suppose you want to sum the quantity sold for either Orchid OR Sunflower.
Notice that it uses multiple OR criteria, like in example #10. But this time, we’ll use an array in the criteria by following the steps below:
Step 1: List each condition separated by a comma and then enclose with curly brackets: {"Orchid","Sunflower"}
Step 2: Write the complete SUMIF formula using the array:
=SUMIF(B2:B9, {"Orchid","Sunflower"},C2:C9)
However, when you look at the result, the value is not correct. It only sums the total for Orchid, which is 520. And you’ll also see 680 next to it, which is the total for Sunflower. Why?
The SUMIF formula takes on an array argument that consists of two values. This forces the formula to return two results separately: 520 and 680. Since we put the formula in cell F5, the function only returns one result for this cell — i.e., the total for Orchid.
For this technique to work, you have to use one more step:
Step 3: Wrap your SUMIF formula in a SUM function, as follows:
=SUM(SUMIF(B2:B9, {"Orchid","Sunflower"},C2:C9))
As you can see, the array criteria make the formula much more compact compared to multiple SUMIFs, as seen in example #10. You can also use arrays with numbers, but you don’t need to double-quote them.
#12: With date range criteria (between two dates)
Unfortunately, the SUMIF Excel formula does not work for this case. Instead, you have to use SUMIFS.
With the following data, suppose you want to sum the total bill for works started between 1-Jun-2021 (cell F3) and 12-Jun-2021 (cell F4). Use the formula below:
=SUMIFS(C2:C11,B2:B11,">="&F3,B2:B11,"<="&F4)
#13: Excel SUMIF by month
Suppose you have the following table and want to find the total bill for works that started in June 2001. To get the result, you can use a SUMIFS function with these two criteria: start dates >= first day of June AND start dates <= last day of June.
Follow the steps below:
Step 1: Type the first date of June 2021 in E3.
Step 2: Change the format of E3 to “mmmm” to display the month name.
Step 3: Write the following formula to F3, then press Enter. Note: The EOMONTH function helps you to find the last day of the month.
=SUMIFS(C2:C11, B2:B11, ">="&E3,B2:B11,"<="&EOMONTH(E3,0))
#14: Excel SUMIF by year
Still using the same data with the previous example, suppose you want to find the total bill for works that started in 2020. To get the result, use SUMIFS with these two criteria: start dates >= first day of 2020 AND start dates <= last day of 2020.
=SUMIFS(C2:C11, B2:B11, ">="&DATE(E3,1,1),B2:B11,"<="&DATE(E3,12,31))
#15: Sum values based on background color
Suppose you have the following profit/loss data and want to sum based on the background color. In Excel, there is no default function to do that. But you can create an Excel VBA function to return the color index of a cell, and then use that index as the criteria in SUMIF.
Follow the steps below:
Step 1: Press Alt+F11 to open the Visual Basic Editor (VBE).
Step 2: Click Insert > Module.
Step 3: Copy-paste the following function to the editor:
Function ColorIndex(CellColor As Range) ColorIndex = CellColor.Interior.ColorIndex End Function
Step 4: Type “Bg Color” as the header of column C. Then, type =ColorIndex(B2)
in C2 and copy the formula down to C7.
Step 5: Use SUMIF to calculate the total profit based on the background color, as follows:
- Formula in F2:
=SUMIF(C2:C7, 19, B2:B7)
- Formula in F3:
=SUMIF(C2:C7, 43, B2:B7)
Read our guide on Excel SUMIFS VBA.
#16: Excel SUMIF to sum across multiple sheets
Suppose you have identical ranges in separate worksheets and want to summarize the total in the first worksheet, as shown in the following screenshot:
To do that, you can use the SUMIF function with INDIRECT, wrapped in SUMPRODUCT.
See the below steps to calculate the summary for the first salesperson (Kelly):
Step 1: List all the sheet names that are going to be summed in the Summary sheet. For example, in E2:E4 as shown below:
Step 2: Write a SUMIF formula for one sheet only – for example, Jan.
=SUMIF(Jan!A2:A6,Summary!A2,Jan!C2:C6)
Step 3: Nest the formula inside SUMPRODUCT.
=SUMPRODUCT(SUMIF(Jan!A2:A6,Summary!A2,Jan!C2:C6))
Step 4: Replace the sheet reference with a list of sheet names. In this case,
- Replace
Jan!A2:A6
withINDIRECT("'"&E2:E4&"'!"&"A2:A6")
- Replace
Jan!C2:C6
withINDIRECT("'"&E2:E4&"'!"&"C2:C6")
The complete formula will be:
=SUMPRODUCT(SUMIF(INDIRECT("'"&E2:E4&"'!"&"A2:A6"),Summary!A2,INDIRECT("'"&E2:E4&"'!"&"C2:C6")))
#17: Sum multiple columns using one criteria
With the following data, suppose you want to calculate how many roses were sold in three months — Jan, Feb, and Mar. You can’t use either SUMIF or SUMIFS in this case. One alternative is to use the SUMPRODUCT function, as follows:
=SUMPRODUCT((A3:A11="Rose")*(B3:D11))
The first expression checks the range A3:A11 and returns an array of TRUE and FALSE. If any cell equals “Rose“, it will return TRUE, otherwise FALSE:
{TRUE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;FALSE;FALSE}
The result above is then multiplied by the values in range B3:D11:
{500,400,300;400,500,200;500,300,400;300,400,500;400,200,500;400,500,200;600,200,300;400,300,200;400,500,300}
The SUMPRODUCT function will calculate the following values, which finally returns 3400.
=SUMPRODUCT({500,400,300;0,0,0;0,0,0;0,0,0;0,0,0;400,500,200;600,200,300;0,0,0;0,0,0})
Limitations of the Excel SUMIF function
After looking at these examples, we are sure you have your own conclusion about the limitations of the SUMIF function. But anyway, here’s the summary:
- You can’t use Excel SUMIF with multiple AND criteria. SUMIF is designed to handle one criteria only. As shown in example #10, you can use SUMIF + SUMIF for multiple OR conditions. However, you can’t use it with multiple AND criteria. For this case, use SUMIFS instead.
- You can’t use Excel SUMIF to sum multiple columns at once. As demonstrated in example #17, you can’t use either SUMIF and SUMIFS to sum multiple columns using one criteria. One of the solutions is to use the SUMPRODUCT function.
- You can’t use Excel SUMIF with an array as its range argument. In example #11, you can see that SUMIF accepts an array in its criteria argument. However, for its range argument, SUMIF requires a cell range. Because of this, you can’t use a formula that returns an array in its range argument — here’s an example:
Suppose you have the following table and want to sum the total bill for works that started in 2020; you can’t use this formula:
=SUMIF(TEXT(B2:B11,"yyyy"),"2020",C2:C11)
Why? That’s because the TEXT function in the above formula will return an array, which SUMIF doesn’t support.
What to do when your Excel SUMIF function is not working
There are times when you’ll find that your SUMIF formula in Excel is not working, or returns inaccurate results. There can be many reasons for that. Most of them have to do with incorrect ranges and defining criteria incorrectly. Thus, we recommend checking the following points:
- Check the order of the arguments used in the formula. For example, if you use three arguments, remember the first argument is the range that contains criteria, not the range you want to sum. You might have confused this with the SUMIFS formula.
- Check the range of cells you use, especially if you copy-pasted the formula from another cell. These include the range you want to sum as well as the range that contains the criteria.
- Ensure that you use double quotation marks (“”) for any criteria other than numeric.
- Check the format of the values involved in the calculation. For example, if you sum values with the time format, ensure you use the correct time format for your range values and the result cells.
- You are sure that you’ve written the correct formula. Still, when you update the sheet, the SUMIF function doesn’t return the updated value? Well, in this case, check the formula calculation option in your spreadsheet. If it’s set to manual, press the F9 key to recalculate the sheet.
Finally, you’ve learned about the SUMIF function, including what it is, its syntax, how to use it, and its differences with SUMIFS. We also have covered various examples, as well as what to do when your function is not working.
We hope this article helped you, but if it didn’t, let us know if you have any comments or suggestions in the comments section below.
-
Senior analyst programmer
Back to Blog
Focus on your business
goals while we take care of your data!
Try Coupler.io