COUNTIF Function
COUNTIF Function
COUNTIF function counts the number of times within the specified range of cells that
perform the specified value as a criterion.
Function syntax:
=COUNTIF (range, criteria)
Range - the range of cells that you want to count the data. There has to be an
ongoing area.
Criteria - a condition that must be met for cell counting. In the case of numeric
values - the condition can look like eg 100
You want to count cells where value is greater than 10. Cells are in C column.
The formula is =COUNTIF(C2:C10,">"&10)
The COUNTIF function and the search criteria (greater than 250 orders) will be added
to row 12 below the data.
Note: The tutorial instructions do not include formatting steps for the worksheet.
This will not interfere with completing the tutorial. Your worksheet will look different
than the example shown, but the COUNTIF function will give you the same results.
2.
3.
Click on cell E12 to make it the active cell. This is where we will enter the
COUNTIF function.
Choose More Functions > Statistical from the ribbon to open the function
drop down list.
4.
Click on COUNTIF in the list to bring up the COUNTIF function's dialog box.
The data that we enter into the two blank rows in the dialog box will form
the arguments of the COUNTIF function.
These arguments tell the function what condition we are testing for and what cells to
count when the condition is met.
2.
Drag select cells E3 to E9 on the worksheet to enter these cell references as the
range to be searched by the function.
3.
4.
Leave the dialog box open for the next step in the tutorial.
5.
2.
3.
4.
Click on cell D12 to enter that cell reference. The function will search the range
selected in the previous step for data that matches whatever data is entered into
this cell.
Click OK to close the dialog box and complete the COUNTIF function.
An answer of zero should appear in cell E12 - the cell where we entered the
function - because we have not yet added the data to the Criteria field (D12).
2.
3.
The criterion of " > 250 " is met in four cells in column E: E4, E5, E8, E9.
Therefore these are the only cells counted by the function.
4.
COUNTIF
Counts the number of cells within a range that meet
the given criteria.
Syntax
COUNTIF(range,criteria)
Range is the range of cells from which you want to
count cells.
Criteria is the criteria in the form of a number,
expression, cell reference, or text that defines which
cells will be counted. For example, criteria can be
expressed as 32, "32", ">32", "apples", or B4.
Remarks
Data
Data
apples
32
oranges
54
peaches
75
apples
86
Formula
Description (result)
=COUNTIF(A2:A5,"apples")
=COUNTIF(A2:A5,A4)
=COUNTIF(A2:A5,A3)+COUNTIF(A2:A5,A2)
=COUNTIF(B2:B5,">55")
=COUNTIF(B2:B5,"<>"&B4)
=COUNTIF(B2:B5,">=32")COUNTIF(B2:B5,">85")
Data
Data
apples
Yes
oranges
NO
peaches
No
apples
YeS
Formula
Description (result)
=COUNTIF(A2:A7,"*es")
=COUNTIF(A2:A7,"?????es")
=COUNTIF(A2:A7,"*")
=COUNTIF(A2:A7,"<>"&"*")
=COUNTIF(B2:B7,"No") / ROWS(B2:B7)
6
7
NOTE To view the number as a percentage, select the cell and click Cells on
the Format menu. Click the Numbertab, and then click Percentage in
the Category box.
arguments via the function wizard. Sign up for the Excel 2013:
Introducing Excel course today to learn to use the built-in
functions offered by Excel.
To use a formula or function in Excel, you need to know how the
function works and what the function does. For an article on
functions, you can read Excel Tutorial: An In-Depth Guide to
Working with your Data, Building Formulas, and Using
Functions available from the Udemy blog.
The COUNTIFS function uses parameters you enter in the function
to count the number of occurrences of data that meet your specific
requirements within the range of data you specify.
The result of the above COUNTIFS formula will be 1. You can see
from the data that Jack made only one sale on the 7th:
The dates refers to the named range we created for our dates and
the Types refers to the named range we created for our sale types.
By adding these fields, searches are simpler in future. All you need
to do is change the start and end dates and change the type to see
the sales of a particular item between two dates.
This is what the result of the above COUNTIFS function will look
like:
For an advanced course that will teach you to harness the power of
Excel function and formulas in your spreadsheets, sign up for the
Mastering Excel with MS-2007, 2010, 2013 course available
from Udemy today.
OR ABOVE,
There are many times that it become necessary to COUNT cells based on multiple
criteria. The examples below will show you 3 ways that this can be done. However,
often themost efficient method is to use a PIVOT TABLE If you are not familiar
with Pivot Tables, I cannot stress enough how much easier spreadsheet life becomes
once you are!
If you are not already aware, the Excel COUNTIF formula/function can only check to see
if specified cells meet one condition, e.g.
COUNTIF Syntax
=countif(range,criteria)
=COUNTIF(A1:A20,">20")
Which would COUNT all numeric cells in the range A1:A20 where values were greater
than 20.
Note the criteria argument is in the form of a number, expression, or text that defines
which cells will be counted. For example, criteria can be expressed as 20, "20", "=20",
">20", "North", "N*".
=COUNTIF($A$1:$A$20,20),
=COUNTIF($A$1:$A$20,">20"),
=COUNTIF($A$1:$A$20,"North"), =COUNTIF($A$1:$A$20,"N*")
Ok, so if we need to count a range of cells where corresponding cells (on the same row
but different column) meet 1, or more conditions we can no longer use the COUNTIF.
The other formulas we can use, in order of their efficiency, are
1)
DCOUNT
2)
&
DCOUNTA DOWNLOAD
SUM
as
ADVANCED
EXAMPLES
an ARRAY
OF
DCOUNT
FORMULA
criteria.
DCOUNTA will count all cells (Text or numeric) where the cells, or corresponding cells
meet a specified criteria.
For all examples I will use the data as shown below. Where A2:E25 has been
named: DataTable
DCOUNT
Count the numbers in a column of a list, or database, that match criteria you specify.
For example;=DCOUNT(DataTable,B2,Criteria)Would Count all cells in B2:B25 that
meet the criteria is the named range:Criteria (shown below)
The top row of the range: Criteria has exact copies of the headings in the range
DataTable . The reference to cell B2 is telling the DCOUNT to count the numbers
in B2:B25 that meet the criteria. We could replace the reference to B2 with the text
"Quantity", or the number 2 as the "Quantity" column is the second column in the
table.
The criteria text "Bourbon" and "Vodka", under the criteria table heading "Description",
tells DCOUNT that either "Bourbon" OR "Vodka" is a match. The same principle is used
for the "Alcohol Content", i.e. "High" OR "Low". This is then seen by DCOUNT as an OR
condition.
Note the repeat of the date under "Use By Date". This is needed when using more than
2 rows as the criteria as a blank cell is seen as a wildcard character. If we wanted to
count only data that lies between 2 dates, we would need have 2 "Use By Date"
headings in our Criteria range and use: >7-Apr-2005 below one of these headings and
<7-Jun-2005 under another. This is then seen by DCOUNT as an AND condition.
DOWNLOAD ADVANCED EXAMPLES OF DCOUNT
DCOUNTA
If we changed the above DCOUNT example to:
=DCOUNT(DataTable,A2,Criteria)
We would always get a result of 0 (zero) regardless of the criteria being met, or not.
This is because DCOUNT will only ever count all numeric cells and there are none in
column A under the "Description" field.
To get a count of these cells, we would need to use the DCOUNTA function which would
count all cells, text or numeric, where the criteria is being met. That is;
=DCOUNTA(DataTable,A2,Criteria)
SUM as an array formula
Normally, the SUM function will add all numeric cells in a specified range. However,
when used as an array formula with criteria used, it will give us a count instead of a
sum.
See
below
example=SUM((A2:A25="Vodka")*(C2:C25>VALUE("7-Apr-
2005"))*(E2:E25="High"))+SUM((A2:A25="Bourbon")*(C2:C25>VALUE("7-Apr2005"))*(E2:E25="Low"))
As with the DCOUNTA example, the above array entered (Ctrl+Shift+Enter) SUM
example would count all rows where the "Use By Date" is greater than 7-Apr-2005, the
"Description" is either "Vodka" OR "Bourbon" and the "Alcohol Content" is "High" OR
"Low".
The reason it gives a count is because each check is returned as TRUE (has a value of
1) or FALSE (has a value of 0). So, in the above example, the third row check would
actually look like;=SUM((0)*(0)*(1))+SUM((1)*(1)*(1))As you can see, unless all 3
criteria are met in at least one of the Sum functions, the result will always be 0
(FALSE). To read about this in detail, see our April edition of our free EXCEL NEWSLETTER
COUNT and IF
=COUNT(IF(A2:A25="Bourbon",IF(C2:C25>VALUE("7-Apr2005"),IF(E2:E25="Low",B2:B25))))
+COUNT(IF(A2:A25="Vodka",IF(C2:C25>VALUE("7-Apr2005"),IF(E2:E25="High",B2:B25))))
The above, does the same as the array SUM example and must be entered by
pushing Ctrl+Shift+Enter. Note we have told the COUNT to count all cells in B2:B25
where the criteria is met. In other words, count all "Quantity" cells where the rest of the
specified rows of the "Description", "Use By Date" and "Alcohol Content" meet the
specified criteria
It is important to know that using the array entered COUNT and IF, or the SUM as
an ARRAY FORMULA over a large number of cells will cause a noticeable slow down in
Excel's recalculation time. The DCOUNT & DCOUNTA are
regard. However, as stated at the very Start , a PIVOT TABLE is better still when done
correctly.
www.free-training-tutorial.com/statistical-functions.html