You are on page 1of 19

SUMIF function

Excel for Office 365  Excel for Office 365 for Mac  Excel for the web  Excel 2019  More...

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.

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. For example, criteria can be expressed as 32, ">32", B5, "32", "apples", 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).

 You can use the wildcard characters—the question mark (?) and asterisk (*)—as the criteria argument. 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 (~) preceding the character.
Remarks

 The SUMIF function returns incorrect results when you use it to match strings longer than 255 characters
or to the string #VALUE!.
 The sum_range argument does not have to be the same size and shape as the range argument. The
actual cells that are added are determined by using the upper leftmost cell in the sum_range argument as the
beginning cell, and then including cells that correspond in size and shape to the range argument. For example:

If range is And sum_range is Then the actual cells are


A1:A5 B1:B5 B1:B5
A1:A5 B1:B3 B1:B5
A1:B4 C1:D4 C1:D4
A1:B4 C1:C2 C1:D4

However, when the range and sum_range arguments in the SUMIF function do not contain the same number of
cells, worksheet recalculation may take longer than expected.

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
SUMIFS function

Excel for Office 365  Excel for Office 365 for Mac  Excel for the web  Excel 2019  More...

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.

This video is part of a training course called Advanced IF functions.

Syntax

SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)

 =SUMIFS(A2:A9,B2:B9,"=A*",C2:C9,"Tom")

Argument name Description


Sum_range    (required) The range of cells to sum.
Criteria_range1    (required) 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.
Criteria1    (required) 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, …    Additional ranges and their associated criteria. You can enter up to 127 range/criteria pairs.
(optional)

 =SUMIFS(A2:A9,B2:B9,"<>Bananas",C2:C9,"Tom")

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.
Quantity Sold Product Salesperson
5 Apples Tom
4 Apples Sarah
15 Artichokes Tom
3 Artichokes Sarah
22 Bananas Tom
12 Bananas Sarah
10 Carrots Tom
33 Carrots Sarah
Formula Description
=SUMIFS(A2:A9, Adds the number of products that begin with A and were sold by Tom. It uses the wildcard
B2:B9, "=A*", C2:C9, character * in Criteria1, "=A*" to look for matching product names in Criterial_range1 B2:B9,
"Tom") and looks for the name "Tom" in Criterial_range2 C2:C9. It then adds the numbers
in Sum_range A2:A9 that meet both conditions. The result is 20.
=SUMIFS(A2:A9, Adds the number of products that aren’t bananas and are sold by Tom. It excludes bananas by
B2:B9, "<>Bananas", using <> in the Criteria1, "<>Bananas", and looks for the
C2:C9, "Tom") name "Tom" in Criterial_range2 C2:C9. It then adds the numbers in Sum_range A2:A9 that
meet both conditions. The result is 30.

Common Problems

Problem Description
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 TRUE and FALSE values for Sum_range are evaluated differently, which may cause
or FALSE values. 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

Do this Description
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 The order of arguments differ between SUMIFS and SUMIF. In particular, the sum_range argument is
between SUMIF and SUMIFS. 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 The Criteria_range argument must contain the same number of rows and columns as
and columns for range the Sum_range argument.
arguments.
COUNTIF function

Use COUNTIF, one of the statistical functions, to count the number of cells that meet a criterion; for example, to
count the number of times a particular city appears in a customer list.

In its simplest form, COUNTIF says:

 =COUNTIF(Where do you want to look?, What do you want to look for?)

For example:

 =COUNTIF(A2:A5,"London")
 =COUNTIF(A2:A5,A4)

Syntax

Examples

To use these examples in Excel, copy the data in the table below, and paste it in cell A1 of a new worksheet.

Data Data
apples 32
oranges 54
peaches 75
apples 86
Formula Description
=COUNTIF(A2:A5,"apples") Counts the number of cells with apples in cells A2
through A5. The result is 2.
=COUNTIF(A2:A5,A4) Counts the number of cells with peaches (the value in
A4) in cells A2 through A5. The result is 1.
=COUNTIF(A2:A5,A2)+COUNTIF(A2:A5,A3) Counts the number of apples (the value in A2), and
oranges (the value in A3) in cells A2 through A5. The
result is 3. This formula uses COUNTIF twice to specify
multiple criteria, one criteria per expression. You
could also use the COUNTIFS function.
=COUNTIF(B2:B5,">55") Counts the number of cells with a value greater than
55 in cells B2 through B5. The result is 2.
=COUNTIF(B2:B5,"<>"&B4) Counts the number of cells with a value not equal to
75 in cells B2 through B5. The ampersand (&) merges
the comparison operator for not equal to (<>) and the
Data Data
value in B4 to read =COUNTIF(B2:B5,"<>75"). The
result is 3.
=COUNTIF(B2:B5,">=32")- Counts the number of cells with a value greater than
COUNTIF(B2:B5,">85") (>) or equal to (=) 32 and less than (<) or equal to (=)
85 in cells B2 through B5. The result is 3.
=COUNTIF(A2:A5,"*") Counts the number of cells containing any text in cells
A2 through A5. The asterisk (*) is used as the wildcard
character to match any character. The result is 4.
=COUNTIF(A2:A5,"?????es") Counts the number of cells that have exactly 7
characters, and end with the letters "es" in cells A2
through A5. The question mark (?) is used as the
wildcard character to match individual characters. The
result is 2.

Common Problems

Problem What went wrong


Wrong value returned for The COUNTIF function returns incorrect results when you use it to
long strings. match strings longer than 255 characters.

To match strings longer than 255 characters, use


the CONCATENATE function or the concatenate operator &. For
example, =COUNTIF(A2:A5,"long string"&"another long string").
No value returned when you Be sure to enclose the criteria argument in quotes.
expect a value.
A COUNTIF formula receives This error occurs when the formula that contains the function
a #VALUE! error when refers to cells or a range in a closed workbook and the cells are
referring to another calculated. For this feature to work, the other workbook must be
worksheet. open.

Best practices

Do this Why
Be aware that Criteria aren't case sensitive. In other words, the string "apples" and the
COUNTIF ignores string "APPLES" will match the same cells.
upper and lower case
in text strings.
Use wildcard Wildcard characters —the question mark (?) and asterisk (*)—can be used
characters. in criteria. A question mark matches any single character. An asterisk
matches any sequence of characters. If you want to find an actual question
Do this Why
mark or asterisk, type a tilde (~) in front of the character.

For example, =COUNTIF(A2:A5,"apple?") will count all instances of "apple"


with a last letter that could vary.
Make sure your data When counting text values, make sure the data doesn't contain leading
doesn't contain spaces, trailing spaces, inconsistent use of straight and curly quotation
erroneous characters. marks, or nonprinting characters. In these cases, COUNTIF might return an
unexpected value.

Try using the CLEAN function or the TRIM function.


For convenience, use COUNTIF supports named ranges in a formula (such as
named ranges =COUNTIF(fruit,">=32")-COUNTIF(fruit,">85"). The named range can be in
the current worksheet, another worksheet in the same workbook, or from
a different workbook. To reference from another workbook, that second
workbook also must be open.

Note: The COUNTIF function will not count cells based on cell background or font color. However, Excel supports
User-Defined Functions (UDFs) using the Microsoft Visual Basic for Applications (VBA) operations on cells based on
background or font color. Here is an example of how you can Count the number of cells with specific cell color by
using VBA.
IFS function

Excel for Office 365  Excel for Office 365 for Mac  Excel for the web  Excel 2019  More...

The IFS function checks whether one or more conditions are met, and returns a value that corresponds to the first
TRUE condition. IFS can take the place of multiple nested IF statements, and is much easier to read with multiple
conditions.

Note: This feature is available on Windows or Mac if you have Office 2019, or if you have an Office 365
subscription. If you are an Office 365 subscriber, make sure you have the latest version of Office.

Simple syntax

Generally, the syntax for the IFS function is:

=IFS([Something is True1, Value if True1,Something is True2,Value if True2,Something is True3,Value if True3)


 

Please note that the IFS function allows you to test up to 127 different conditions. However, we don't recommend
nesting too many conditions with IF or IFS statements. This is because multiple conditions need to be entered in
the correct order, and can be very difficult to build, test and update.

Technical details

Example 1

The formula for cells A2:A6 is:

  =IFS(A2>89,"A",A2>79,"B",A2>69,"C",A2>59,"D",TRUE,"F")
Which says IF(A2 is Greater Than 89, then return a "A", IF A2 is Greater Than 79, then return a "B", and so on and
for all other values less than 59, return an "F").

Example 2

The formula in cell G7 is:

  =IFS(F2=1,D2,F2=2,D3,F2=3,D4,F2=4,D5,F2=5,D6,F2=6,D7,F2=7,D8)

Which says IF(the value in cell F2 equals 1, then return the value in cell D2, IF the value in cell F2 equals 2, then
return the value in cell D3, and so on, finally ending with the value in cell D8 if none of the other conditions are
met).

Remarks

 To specify a default result, enter TRUE for your final logical_test argument. If none of the other conditions
are met, the corresponding value will be returned. In Example 1, rows 6 and 7 (with the 58 grade) demonstrate
this.
  If a logical_test argument is supplied without a corresponding value_if_true, this function shows a
"You've entered too few arguments for this function" error message.
  If a logical_test argument is evaluated and resolves to a value other than TRUE or FALSE, this function
returns a #VALUE! error.
  If no TRUE conditions are found, this function returns #N/A error.
COUNTIFS function

Excel for Office 365  Excel for Office 365 for Mac  Excel for the web  Excel 2019  More...

The COUNTIFS function applies criteria to cells across multiple ranges and counts the number of times all criteria
are met.

This video is part of a training course called Advanced IF functions.

Syntax

COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)

The COUNTIFS function syntax has the following arguments:

 criteria_range1    Required. The first range in which to evaluate the associated criteria.


 criteria1    Required. The criteria in the form of a number, expression, cell reference, or text that define
which cells will be counted. For example, criteria can be expressed as 32, ">32", B4, "apples", or "32".
 criteria_range2, criteria2, ...    Optional. Additional ranges and their associated criteria. Up to 127
range/criteria pairs are allowed.

Important: Each additional range must have the same number of rows and columns as
the criteria_range1 argument. The ranges do not have to be adjacent to each other.

Remarks

 Each range's criteria is applied one cell at a time. If all of the first cells meet their associated criteria, the
count increases by 1. If all of the second cells meet their associated criteria, the count increases by 1 again, and so
on until all of the cells are evaluated.
 If the criteria argument is a reference to an empty cell, the COUNTIFS function treats the empty cell as a 0
value.
 You can use the wildcard characters— the question mark (?) and asterisk (*) — in criteria. A question
mark matches any single character, and an asterisk matches any sequence of characters. If you want to find an
actual question mark or asterisk, type a tilde (~) before the character.

Example 1

Copy the example data in the following tables, 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.
Salesperson Exceeded Q1 quota Exceeded Q2 Exceeded Q3
quota quota
Davidoski Yes No No
Burke Yes Yes No
Sundaram Yes Yes Yes
Levitan No Yes Yes
Formula Description Result
=COUNTIFS(B2:D2,"=Yes") Counts how many times Davidoski exceeded a sales quota 1
for periods Q1, Q2, and Q3 (only in Q1).
=COUNTIFS(B2:B5,"=Yes",C2:C5,"=Yes") Counts how many salespeople exceeded both their Q1 and 2
Q2 quotas (Burke and Sundaram).
=COUNTIFS(B5:D5,"=Yes",B3:D3,"=Yes") Counts how many times Levitan and Burke exceeded the 1
same quota for periods Q1, Q2, and Q3 (only in Q2).

Example 2

Data  
1 5/1/2011
2 5/2/2011
3 5/3/2011
4 5/4/2011
5 5/5/2011
6 5/6/2011
Formula Description Result
=COUNTIFS(A2:A7,"<6",A2:A7,">1") Counts how many numbers between 1 and 6 (not including 1 and 6) are contained 4
in cells A2 through A7.
=COUNTIFS(A2:A7, Counts how many rows have numbers that are less than 5 in cells A2 through A7, 2
"<5",B2:B7,"<5/3/2011") and also have dates that are are earlier than 5/3/2011 in cells B2 through B7.
=COUNTIFS(A2:A7, "<" & A6,B2:B7,"<" Same description as the previous example, but using cell references instead of
& B4) constants in the criteria.
Use nested functions in a formula

Excel for Office 365  Excel for the web  Excel 2019  Excel 2016  Excel 2013  Excel 2010  More...

Using a function as one of the arguments in a formula that uses a function is called nesting, and we’ll refer to that
function as a nested function. For example, by nesting the AVERAGE and SUM function in the arguments of the IF
function, the following formula sums a set of numbers (G2:G5) only if the average of another set of numbers
(F2:F5) is greater than 50. Otherwise, it returns 0.

The AVERAGE and SUM functions are nested within the IF function.

You can nest up to 64 levels of functions in a formula.

WindowsWeb

1. Click the cell in which you want to enter the formula.


2. To start the formula with the function, click Insert Function   on the formula bar   .

Excel inserts the equal sign (=) for you.

3. In the Or select a category box, select All.

If you are familiar with the function categories, you can also select a category.

If you're not sure which function to use, you can type a question that describes what you want to do in the Search
for a function box (for example, "add numbers" returns the SUM function).

4. To enter another function as an argument, enter the function in the argument box that you want.

The parts of the formula displayed in the Function Arguments dialog box reflect the function that you selected in
the previous step.

If you clicked IF, the Function arguments dialog box displays the arguments for the IF function. To nest another
function, you can enter it into the argument box. For example, you could enter SUM(G2:G5) in
the Value_if_true box of the IF function.

5. Enter any additional arguments that are needed to complete your formula.

Instead of typing cell references, you can also select the cells that you want to reference. Click   to minimize the
dialog box, select the cells you want to reference, and then click   to expand the dialog box again.

Tip: For more information about the function and its arguments, click Help on this function.
6. After you complete the arguments for the formula, click OK.

Examples

The following shows an example of using nested IF functions to assign a letter grade to a numeric test score.

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.

Score
45
90
78
Formula Description Result
'=IF(A2>89,"A",IF(A2>79,"B", Uses nested IF conditions to =IF(A2>89,"A",IF(A2>79,"B",IF(A2>69,"C",IF(A2>59,"D","F"))))
IF(A2>69,"C",IF(A2>59,"D","F")))) assign a letter grade to the
score in cell A2.
'=IF(A3>89,"A",IF(A3>79,"B", Uses nested IF conditions to =IF(A3>89,"A",IF(A3>79,"B",IF(A3>69,"C",IF(A3>59,"D","F"))))
IF(A3>69,"C",IF(A3>59,"D","F")))) assign a letter grade to the
score in cell A3.
'=IF(A4>89,"A",IF(A4>79,"B", Uses nested IF conditions to =IF(A4>89,"A",IF(A4>79,"B",IF(A4>69,"C",IF(A4>59,"D","F"))))
IF(A4>69,"C",IF(A4>59,"D","F")))) assign a letter grade to the
score in cell A4.

Tips: 

 To learn more about formulas in general see Overview of formulas.


 For a list of available functions, see Excel functions (alphabetical) or Excel functions (by category).
Using functions and nested functions in Excel formulas

Excel for Office 365  Excel 2019  Excel 2016  Excel 2013  Excel 2010  Excel 2007

Functions are predefined formulas that perform calculations by using specific values, called arguments, in a
particular order, or structure. Functions can be used to perform simple or complex calculations. You can find all of
Excel's functions on the Formulas tab on the Ribbon:

 Excel function syntax

The following example of the ROUND function rounding off a number in cell A10 illustrates a function's syntax.

1. Structure. The structure of a function begins with an equal sign (=), followed by the function name, an opening
parenthesis, the arguments for the function separated by commas, and a closing parenthesis.

2. Function name. For a list of available functions, click a cell and press SHIFT+F3, which will launch the Insert
Function dialog.
3. Arguments. Arguments can be numbers, text, logical values such as TRUE or FALSE, arrays, error values such as
#N/A, or cell references. The argument you designate must produce a valid value for that argument. Arguments
can also be constants, formulas, or other functions.

4. Argument tooltip. A tooltip with the syntax and arguments appears as you type the function. For example,
type =ROUND( and the tooltip appears. Tooltips appear only for built-in functions.

Note: You don't need to type functions in all caps, like =ROUND, as Excel will automatically capitalize the function
name for you once you press enter. If you misspell a function name, like =SUME(A1:A10) instead of =SUM(A1:A10),
then Excel will return a #NAME? error.

 Entering Excel functions

When you create a formula that contains a function, you can use the Insert Function dialog box to help you enter
worksheet functions. Once you select a function from the Insert Function dialog Excel will launch a function
wizard, which displays the name of the function, each of its arguments, a description of the function and each
argument, the current result of the function, and the current result of the entire formula.
To make it easier to create and edit formulas and minimize typing and syntax errors, use Formula AutoComplete.
After you type an = (equal sign) and beginning letters of a function, Excel displays a dynamic drop-down list of valid
functions, arguments, and names that match those letters. You can then select one from the drop-down list and
Excel will enter it for you.
 Nesting Excel functions

In certain cases, you may need to use a function as one of the arguments of another function. For example, the
following formula uses a nested AVERAGE function and compares the result with the value 50.

1. The AVERAGE and SUM functions are nested within the IF function.

Valid returns    When a nested function is used as an argument, the nested function must return the same type of
value that the argument uses. For example, if the argument returns a TRUE or FALSE value, the nested function
must return a TRUE or FALSE value. If the function doesn't, Excel displays a #VALUE! error value.

Nesting level limits    A formula can contain up to seven levels of nested functions. When one function (we'll call
this Function B) is used as an argument in another function (we'll call this Function A), Function B acts as a second-
level function. For example, the AVERAGE function and the SUM function are both second-level functions if they
are used as arguments of the IF function. A function nested within the nested AVERAGE function is then a third-
level function, and so on.

You might also like