SumIf CountIf
SumIf CountIf
https://www.vertex42.com/blog/excel-formulas/sumif-and-countif-in-excel.html
This workbook contains examples from the article "SUMIF and COUNTIF in Excel." Regarding copyright and s
book. You may use the ideas and techniques and formulas explained here, but you may not reproduce this wo
portions from it, just as you would not do so with a book. Thank you. - Jon Wittwer
EXAMPLES
The SUMIF and COUNTIF functions allow you to conditionally sum or count cells based on a single criteria. Th
with almost all versions of Excel. The SUMIFS and COUNTIFS functions allow you to conditionally sum or cou
multiple criteria, but are only available beginning with Excel 2007.
NOTES Comparisons are based on the value stored in the cell, NOT on how the cell is formatted.
The sum_range and criteria_range arguments can be references, named ranges or formulas
INDEX, OFFSET, or INDIRECT).
The SUMIF and COUNTIF functions ignore errors in both the sum range and the criteria ran
advantages of using these functions instead of array formulas or SUMPRODUCT.
See the articles on the Microsoft sites for information about what happens when the sum_ra
the same length.
Alternate: =SUMPRODUCT(sales,1*(category="student"))
Alternate: =SUMPRODUCT(sales,1*(MID(category,2,1)="u"))
Criteria is an Alphabetical Text Order Comparison ("<C")
Note: Not case-sensitive. Will ignore numeric values unless you use not equal to (like "<>M").
symbols are sorted based on their ascii or unicode values: a string beginning with "#" would be
string beginning with "A" and a string beginning with "Ω" would be greater than a string beginn
Alternate: =SUMPRODUCT(sales,1*(model<"C"))
Alternate: =SUMPRODUCT(1*(model<>"A"))
Alternate: =SUMPRODUCT(sales,1*(model<>"A"))
Note: Will also count cells that contain formulas returning the empty value "". This is one of the
a NULL function is needed.
Note: A cell formatted to display blank, such as when the value is zero, will not necessarily be
blank or empty. Comparisons are based on the value stored in the cell, not how the cell is form
Alternate: =SUMPRODUCT(1*(on_sale=""))
Alternate: =SUMPRODUCT(1*(price<40))
Alternate: =SUMPRODUCT(1*(price>=50))
Alternate: =SUMPRODUCT(sales,1*(price<A1))
Formula: =SUM(SUMIF(model,{"A","B"},sales))
Note: For this technique to work, the conditions must not overlap. For example, the condition "
overlap with the condition "=yes". The condition "<40" would overlap with the condition ">20". I
overlap, you may end up counting or adding a value twice. If there is a possibility of conditions
then you may need to use a SUMPRODUCT formula.
The key to avoid double-counting is to recognize that for a logical OR condition, TRUE+FALSE=1 and TRUE+
means that for a logical OR condition, we can check whether the sum of two or more conditions is > 0.
MAX-IF Formula
Equal to a Date
The table to the right shows the date Mar 1, 2017 as a date value formatted two different
ways and also three different text values. Each of the dates are displayed differently, but
when using the criteria "=3/1/17" Excel will count them all as long date is a recognized date
format. This means that Excel is recognizing the criteria as a date and it is also converting the
date_range values to dates if it can.
Examples: =COUNTIF(date_range,"=3/1/17")
=COUNTIF(date_range,DATE(2017,3,1))
=COUNTIF(date_range,"March 1, 2017")
=COUNTIF(date_range,"Mar 1st 2017")
When using a < or > comparison, Excel converts the criteria to a date value, but it does not
convert the date_range values to date values. In the example to the right, all 5 dates are
greater than Jan 1, 2017. However, the COUNTIF function does not convert the two text
values to dates.
Formula: =COUNTIF(date_range,">1/1/2017")
See the Income and Expense Report example below to see this formula in action.
Formula: =SUMIFS(sum_range,dates,">=1/1/2017",dates,"<1/31/2017")
To sum values between (and including) two dates would be similar to the fourth example above. The following
where 1/1/2017 <= date <= 1/31/2017.
Formula: =SUMIF(sum_range,date_range,"<=1/31/2017")-SUMIF(sum_range,date_range,"<1/1/2017
Value Formula
-1 =COUNTIF(range,"<2") + COUNTIF(range,">3")
0 =SUM(COUNTIF(range,{"<2",">3"}))
1 =COUNT(range) - COUNTIFS(range,">=2",range,"<=3")
2 CSE array formula: =SUM(COUNTIF(range,A1:A2))
3
4
5
Check Register
Date Payee Category Amount Balance
1/1/2018 Carry-Over 3,000.00 3,000.00
1/2/2018 Auto Stop Fuel (35.42) 2,964.58
1/5/2018 Smith's Groceries (15.32) 2,949.26
1/15/2018 Albertsons Groceries (67.98) 2,881.28
1/31/2018 Paycheck Wages 2,354.00 5,235.28
2/5/2018 A Express Debt (156.23) 5,079.05
2/9/2018 ABC Insure Insurance (576.23) 4,502.82
2/15/2018 Auto Stop Fuel (24.12) 4,478.70
2/18/2018 Albertsons Groceries (76.12) 4,402.58
2/28/2018 Paycheck Wages 2,354.00 6,756.58
REFERENCES
Matches …
"yes" or "Yes" (not case-sensitive)
second letter is "s" or "S"
values alphabetically less than C
numeric values equal to 20
numeric values less than or equal to 20
numeric values greater than or equal to 20
values not equal to the value 0
values that are not blank (="" is considered non-blank)
values that are blank and formulas returning ""
Matches the value in cell A42
Matches "3/1/17" or "Mar 3, 2017" or date values equal to 3/1/2017
(="")
Result
700
700
700
Result
70
0
"?u*" don't recognize wildcard characters.
70
Model < Result
C 3330
C 3330
Result
6
Result
6660
6660
Result
7770
Result
4
Result
6
Result
3
Result
4
Value Result
35 $ 100.00
35 $ 100.00
Category Result
student $ 700.00
*e* $ 7,770.00
>m $ 700.00
Criteria Result
>50 $ 4,060.00
<><50 $ 7,770.00
Result
1300
3330
3330
Result
3330
7170
Result
50
me interesting things, depending on
range are stored as date values or text
Date Values
3/1/2017 (date value)
1-Mar-17 (date value)
3/1/17 (text value)
Mar 1, 2017 (text value)
Mar 1st 2017 (text value - unrecognized date format)
Result: 4
4
4
1
Date Values
3/1/2017 (date value)
4/1/2017 (date value)
5/1/2017 (date value)
Apr 1, 2017 (text value)
May 1, 2017 (text value)
Result: 3
Result: 3
or FIND
k to using array formulas or
nsitive matches.
Value Result
stu 0
Stu 700
s1<x<4
which means x > 1 AND x < 4), it is also simple to use
ults of the condition x < 4.
Result
(range,"<=1") 2
(range,"<1") 3
F(range,"<=1") 3
F(range,"<1") 4
Result
2
mple above. The following formula would sum values
ge,date_range,"<1/1/2017")
s x < 2 OR x > 3
arily handle OR conditions, such as X < 2 OR X > 3. The
Result
5
5
5
5 <2 >3
2,354.00
(24.12)
(76.12)
(576.23)
(156.23)