Professional Documents
Culture Documents
This tutorial explains the Excel SUMIF function in plain English and provides a numbers of
SUMIF formula examples for numbers, text, dates and wildcards.
If you are faced with the task that requires conditional sum in Excel, the SUMIF function is
what you need. This tutorial will briefly explain the function's syntax and general usage, and
then you will extend the new knowledge in practice with a number of SUMIF formula
examples.
A good thing is that the SUMIF function is identical in all Excel versions, from 2016 to 2003.
Another great news is that once you've invested some time in learning SUMIF, it will take you
very little effort to get the insight of other "IF" functions such as SUMIFS, COUNTIF,
COUNTIFS, AVERAGEIF etc.
If you've happened to read the COUNTIF tutorial on this blog, you won't have any difficulties
with understanding Excel SUMIF because its syntax and usage is analogous. So, the syntax of
the SUMIF function is as follows:
As you see, the SUMIF function has 3 arguments - first 2 are required and the 3rd one is
optional.
1. range - the range of cells to be evaluated by your criteria, for example A1:A10.
2. criteria - the condition that must be met. The criteria may be supplied in the form of a
number, text, date, logical expression, a cell reference, or another Excel function. For
example, you can enter the criteria such as "5", "cherries", "10/25/2014", "<5", "A1", etc.
Note. Please pay attention that any text criteria or criteria containing mathematical
symbols must be enclosed in double quotation marks ("). For numerical criteria, double
quotation marks are not required.
3. sum_range - the cells to sum if the condition is met. This argument is optional, and you
need to use it only if you want to sum cells other than defined in the range argument. If
the sum_range argument is omitted, Excel will sum the same cells to which the criteria is
applied (i.e. specified in the range argument).
1/13
To illustrate the Excel SUMIF syntax better, let's consider the following example.
Suppose you have a list of products in column A and corresponding amounts in column
C. You want to know the sum of all amounts relating to a given product, e.g. bananas.
range - A2:A8
criteria - "bananas"
sum_range - C2:C8
Putting this together, you get: =SUMIF(A2:A8, "bananas", C2:C8)
This formula example demonstrates the simplest usage of the SUMIF function with the
text criteria. Instead of text, you can include a number, date or a cell references in your
criteria. For instance, you can re-write the above formula so that it references the cell
containing the name of the product to be summed:
=SUMIF(A2:A8,F1,C2:C8)
Note. The sum_range parameter actually specifies only the upper leftmost cell of the
range to be summed. The remaining area is defined by the dimensions of the range
argument.
2/13
In practice, this means that the sum_range argument does not necessarily have to be of the
same size as the range argument, i. e. it may have a different number of rows and columns.
However, the first cell (i.e. the top left cell) of the sum range must always be the right one. For
example, in the above SUMIF formula, you can supply C2, or C2:C4, or even C2:C100 as the
sum_range argument, and the result will still be the same. However, the best practice is to
provide equally sized range and sum_range.
The point is that Microsoft Excel cannot rely on the user's ability to provide matching range and
sum_range parameters, so to avoid possible inconsistency issues and prevent errors,
Microsoft Excel determines the sum range on its own in the following way. It takes the top left
cell in the sum_range argument as the beginning cell (C2 in our Excel SUMIF example), and
then includes as many columns and rows as contained in the range argument (in our case, it's
1 column x 7 rows, i.e. C2:C8).
Note. Please pay attention that in Excel SUMIF formulas, a comparison operator followed by a
number or text should always be enclosed in double quotes ("").
Sum if greater > =SUMIF(A2:A10, Sum the values over 5 in cells A2:A10.
than ">5")
Sum if less < =SUMIF(A2:A10, " Sum the values in cells B2:B10 if a corresponding
than <10", B2:B10) value in column A is less than 10.
Sum if equal to = =SUMIF(A2:A10, Sum the values in cells A2:A10 that are equal to the
(can be "="&D1) value in cell D1.
omitted) or
=SUMIF(A2:A10,D1)
Sum if not <> =SUMIF(A2:A10, " Sum the values in cells B2:B10 if a corresponding
equal to <>"&D1, B2:B10) cell in column A is not equal to the value in cell D1.
Sum if greater >= =SUMIF(A2:A10, Sum the values greater than or equal to 5 in the
than or equal to ">=5") range A2:A10.
Sum if less <= =SUMIF(A2:A10, " Sum the values in cells B2:B10 if a corresponding
than or equal to <=10", B2:B10) value in column A is less than or equal to 10.
Please pay attention that you will need different SUMIF formulas for exact and partial match,
as demonstrated in the table below.
Sum if Exact match: Sum values in cells C2:C8 if a corresponding cell in column A contains
equal =SUMIF(A2:A8, exactly the word "bananas" and no other words or characters. Cells
to "bananas", containing "green bananas", "bananas green" or "bananas!" will not be
C2:C8) included.
Partial match: Sum values in cells C2:C8 if a corresponding cell in column A contains the
=SUMIF(A2:A8, word "bananas", alone or in combination with any other words. Cells
"*bananas*", containing "green bananas" or "bananas green" will be summed.
C2:C8)
Sum if Exact match: Sum values in cells C2:C8 if a corresponding cell in column A contains any
not =SUMIF(A2:A8, value other than "bananas". If a cell contains "bananas" together with some
equal "<>bananas", other words or characters like "yellow bananas" or "bananas yellow", such
to C2:C8) cells will be summed.
Partial match: Sum values in cells C2:C8 if a corresponding cell in column A does not
=SUMIF(A2:A8, contain the word "bananas", alone or in combination with any other words.
" Cells containing "yellow bananas" or "bananas yellow" will not be summed.
<>*bananas*",
C2:C8)
For more information about partial match, please see SUMIF examples with wildcard
characters.
And now, let's see the exact "Sum if not equal to" formula in action. As illustrated in the
screenshot below, it adds in-stock amounts of all products other than "goldfinger bananas":
Note. Like most of other Excel functions, SUMIF is case-insensitive, meaning that "
<>bananas", "<>Bananas" and "<>BANANAS" will produce exactly the same result.
In this case, you won't have to change the formula to conditionally sum values based on
another criteria - you will simply type a new value in a referenced cell.
Note. When you use a logical expression with a cell reference, you must use the double
quotes ("") to start a text string and ampersand (&) to concatenate and finish the string off, for
example "<>"&F1.
The "equal to" operator (=) can be omitted before a cell reference, therefore both of the below
formulas are equivalent and correct:
Suppose, you want to sum amounts relating to all sorts of bananas. The following SUMIF
formulas will work a treat:
=SUMIF(A2:A8, "*bananas*", C2:C8) - the criteria includes text enclosed in asterisks (*).
5/13
=SUMIF(A2:A8, "*"&F1&"*", C2:C8) - the criteria includes a cell reference enclosed in
asterisks, please notice the use of ampersand (&) before and after a cell reference to
concatenate a string.
If you want to count only those cells that start or end with certain text, add just one * either
before or after the text:
Tip. To use wildcards with cell references, combine them with the help of the concatenation
operator (&). In this example, you could also use the following formula to sum all "bananas" in
stock: =SUMIF(A2:A8, "*"&F1&"*", C2:C8)
In case you want to sum some values that are exactly 6 letters long, you would use the
following formula:
If your worksheet contains different data types and you only want to sum cells corresponding to
text values, the following SUMIF formulas will come in handy:
=SUMIF(A2:A8,"*",C2:C8) - includes seemingly empty cells that contain zero length strings
returned by some other formulas, e.g. ="".
Both of the above formulas ignore non-text values such as errors, booleans, numbers and
dates.
6/13
Example 4. Treat * or ? as usual characters
If you want either * or ? to be treated as a literal rather than a wildcard, then use the preceding
tilde (~). For example, the following SUMIF formula will add values in cells C2:C8 if a cell in
column A in the same row contains a question mark:
If you want to sum just a few numbers, say 5, you can type them directly in the formula, like
this:
=SUM(LARGE(B1:B50,ROW(INDIRECT("1:15"))))
=SUM(SMALL(B1:B50,ROW(INDIRECT("1:15"))))
Since these are array formulas, remember to enter them in the array-way by pressing Ctrl +
Shift + Enter.
If you'd rather not change the formula every time you want to sum a different number of cells,
you can put that number in some cell instead of entering it directly in the formula. And then,
you can use the ROW and INDIRECT functions as demonstrated above and refer to a cell
containing the variable, cell E1 in our case:
8/13
Remember, these are array formulas, so you have to press Ctrl + Shift + Enter to complete
them.
=SUMIF(A2:A10,"=",C2:C10)
If "blank" includes zero length strings (for example, cells with a formula like =""), then use "" as
the criteria:
=SUMIF(A2:A10,"",C2:C10)
Both of the above formulas evaluate cells in column A and if any empty cells are found, the
corresponding values from column C are added.
=SUMIF(A2:A10,"<>",C2:C10)
The above formula counts values corresponding to all non-empty cells, including zero length
strings.
If you want to sum values corresponding to the dates that are greater than, less than or equal
to the date you specify, then use the comparison operators that we've discussed a moment
ago. A few Excel SUMIF formula examples follow below:
9/13
Criteria Formula Example Description
In case you want to sum values based on a current date, then you have to use Excel SUMIF in
combination with the TODAY() function as demonstrated below:
Sum values corresponding to a prior date, i.e. before today. =SUMIF(B2:B9, "<"&TODAY(), C2:C9)
Sum values corresponding to a future date, i.e. after today. =SUMIF(B2:B9, ">"&TODAY(), C2:C9)
Sum values if a date occurs in a week (i.e. today + 7 days). =SUMIF(B2:B9, "="&TODAY()+7,
C2:C9)
The screenshot below illustrates how you can use the last formula to find the total amount of all
products that ship in a week.
The following question is frequently asked on Excel forums and blogs - "How do I sum
between two dates?"
10/13
The answer is to use a combination, or more precisely, the difference of 2 SUMIF functions. In
Excel 2007 and higher, you can also use the SUMIFS function that allows multiple criteria,
which is even a better option. While the latter is the subject of our next article, an example of
the SUMIF formula follows below:
This formula sums up the values in cells C2:C9 if a date in column B is between 1-Oct-2014
and 31-Oct-2014, inclusive.
This formula might seem a bit tricky at first sight, but upon a closer look, it appears quite
simple. The first SUMIF function adds up all the cells in C2:C9 where the corresponding cell in
column B is greater than or equal to the start date (Oct-1 in this example). Then you just have
to subtract any values that fall after the end date (Oct-31), which are returned by the second
SUMIF function.
So, how do you find the total of apples sold in all the states in the past three months?
11/13
As you remember, the dimensions of sum_range are determined by the dimensions of the
range parameter. That is why you cannot use the formula like =SUMIF(A2:A9,"apples",C2:E9)
because it will add up the values corresponding to "Apples" in column C only. This is not what
we are looking for, right?
The most logical and simplest solution that suggests itself is to create a helper column that
calculates individual sub-totals for each row and then reference that column in the sum_range
criteria.
Go ahead and place a simple SUM formula in cell F2, then fill down column F: =SUM(C2:E2)
After that, you can write a usual SUMIF formula like this:
In the above formulas, sum_range is exactly of the same size as range, i.e. 1 column and 8
rows, and therefore they return the correct result:
If you'd rather do without a helper column, then you can write a separate SUMIF formula for
each of the columns you want to sum, and then add the returned numbers using the SUM
function:
Another way is using a more complex array formula (don't forget to press Ctrl + Shift + Enter):
{=SUM((C2:C9+D2:D9+E2:E9)*(--(A2:A9=I1)))}
For example, the following formula will sum the values in cells F2:F9 in Sheet 1 of Book 1 if a
corresponding cell in column A if the same sheet contains "apples":
=SUMIF([Book1.xlsx]Sheet1!$A$2:$A$9,"apples",[Book1.xlsx]Sheet1!$F$2:$F$9)
However, this formula won't work as soon as Book 1 is closed. This happens because the
ranges referenced by SUMIF formulas in closed workbooks get de-referenced into arrays, and
since no arrays are allowed in the range and sum_range arguments, a SUMIF formula will
throw a #VALUE! error.
3. To avoid problems, make sure range and sum_range are of the same size.
As noted in the beginning of this tutorial, in modern versions of Microsoft Excel, the range and
sum_range parameters does not have to be equally sized. In Excel 2000 and older, unequally
sized range and sum_range can cause problems. However, even in the most recent versions
of Excel 2010 and Excel 2016, complex SUMIF formulas where sum_range has less rows
and/or columns than range are capricious. That is why it's considered a good practice to
always have the range and sum_range arguments of the same size and shape.
The Excel SUMIF examples described in this tutorial only touch on some of the basic usages
of this function. In the next article, we'll investigate advanced formulas that harness the real
power of SUMIF and SUMIFS and let you sum by multiple criteria. Please stay tuned and
thank you for reading!
13/13