Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Counting Records Matching Multiple Criteria.
Written by Allen Wyatt (last updated January 9, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
It is not unusual to use Excel to create small databases. For instance, you might keep a list of your poodle-breeders club members in Excel, or you might use it to maintain a list of your active sales contacts. In those instances, you might wonder how you could get a count of the number of records that meet more than one criteria.
Let's say that you are analyzing your membership list, and you wanted to determine a count of the records in which the gender column contains "F" and the city column contains a particular city, such as "Norwood". This, of course, would be helpful because it would answer the burning question of how many female members of your group live in Norwood.
Excel includes a number of worksheet functions that are handy for determining the count of records in a list. How you can use these in a situation where two criteria must be met may not be immediately obvious. Let's examine six specific ways you can achieve the desired goal of female members from Norwood. (Assume that column C is the gender column and column F is the city column.)
The first way to solve the problem is through the use of the COUNTIFS function. If your gender column is column C and your city column is column F, you could use the following formula:
=COUNTIFS(C1:C500,"F",F1:F500,"Norwood")
It looks in the gender column (C) for any cells containing "F" and the city column (F) for any cells containing "Norwood." The result is the number of records that satisfy both criteria.
A second approach is to use the DCOUNTA function. This function allows you to define a set of criteria and use those criteria as the basis for analyzing a list of data. Like all the data functions in Excel, DCOUNTA relies upon three parameters: the data range, the column to use in the comparisons, and the criteria range. To use the function, set up a criteria table in an unused area of your worksheet. For instance, you could set up the following in cells AA1 through AB2: (See Figure 1.)
Figure 1. The criteria table for the DCOUNTA function.
Then, assuming your original data table is in cells A1:K500 (obviously a large poodle breeders' club), then you could use the following to determine the count:
=DCOUNTA(A1:K500,1,AA1:AB2)
The result is a count that meets the criteria you specified in AA1:AB2. Note, as well, that the names you used in AA1 and AB1 must exactly match the labels you used in your table records. When they do, the contents of the Gender column (column C) must be "F" and the contents of the City column (column F) must be "Norwood" in order for the record to be added to the count.
The third solution is to use an array formula to return a single answer. The array formula interestingly uses the SUM function and a little bit of Boolean arithmetic to determine if a record should be counted. Consider the following:
=SUM((C2:C500="F")*(F2:F500="Norwood"))
Simply type the above formula in a cell and then finish it by pressing Ctrl+Shift+Enter; this lets Excel know you are entering an array formula. The formula works because it compares the contents of each row in the array, in turn, according to the criteria specified in the formula. It first compares the contents of the C column with "F"; if it matches, then the comparison returns True, which is the numeric value 1. The contents of column F are then compared to "Norwood". If that comparison is true, then 1 is returned. Thus, 1 * 1 would equal 1, and this is added to the SUM of the array. If either comparison is False, then the numeric value 0 is returned, and 1 * 0 equals 0 (as does 0 * 0 and 0 * 1), which doesn't affect the running SUM.
A fourth and closely related approach is to use the SUMPRODUCT function, but not in an array formula. You could simply use the following in any cell where you wanted to know if the two criteria are met:
SUMPRODUCT((C2:C500="F")*(F2:F500="Norwood"))
Remember, this is not an array formula, so you don't need to press Ctrl+Shift+Enter. The formula works, again, through the magic of Boolean math.
A fifth possible solution, which is a bit more manual than those discussed already, is to use the AutoFilter feature along with a subtotal. Assuming your data records are in A1:K500, with column labels in row 1, you would follow these steps:
=SUBTOTAL(3,C2:C500)
This formula causes the SUBTOTAL function to apply the COUNTA function to derive a subtotal. In other words, it returns a count of all records that are displayed by the filtering; this is the count desired.
A sixth approach is to use the Conditional Sum Wizard to come up with a formula for you. (The Conditional Sum Wizard is available as an Excel add-in for Excel 2007 and earlier versions; it is enabled on most systems by default. It was removed from Excel 2010.) Follow these steps to use the Conditional Sum Wizard:
Figure 2. The Conditional Sum Wizard.
The result is a formula, appropriate for the conditions you specified, in the cell you selected in step 1.
There are undoubtedly countless other possible solutions you could use to figure out the count of records. These, however, are the "pick of the lot," and allow you to determine the answer quickly and easily.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7759) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Counting Records Matching Multiple Criteria.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
When you need to determine an average based on a very small selection of cells from a large dataset, based on multiple ...
Discover MoreDo you need to determine the top three values in a range of columns? The techniques discussed in this tip will come in ...
Discover MoreUsing a formula to find information in a text value is easy. Using a formula to find either of two text values within a ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-01-12 10:40:50
Ken
Why not just create a pivot table and use the Count function? Then you can slice and dice the data any way you want without needing to create a formula for each scenario.
2021-01-11 12:44:10
rkeev
Use the Plus + sign instead of the * sign for Or conditions
2021-01-09 19:00:14
John Laird
Or Filters?
2021-01-09 11:16:42
Joop
why not use a pivot table?
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments