Count Records That Match a Criterion
March 25, 2022 - by Bill Jelen

Problem: I have a large data set. I want to count the number of records that meet a certain criterion.

Strategy: You use the COUNTIF
function, which requires two arguments: a range of cells that you want to test and a criteria. To count the records where the gender is M, you use =COUNTIF(B5:B60,“M”)
.

Note that the second argument, “M”, tells Excel to count records that are equal to M. Because this function is not case-sensitive, the function will count cells with values of M or m.
If you want to count the records where the age is a specific number, you can write the formula either with or without quotes around the number:
=COUNTIF(D5:D60,32)
=COUNTIF(D5:D60,“32”)
You can also establish a criterion to look for items that are below or above a certain number:
=COUNTIF(D5:D60,“<21”)
A criterion can include a wildcard character. To find any text that contains XYZ, you use the following formula:
=COUNTIF(A2:A999,”*XYZ*”)
This article is an excerpt from Power Excel With MrExcel
Title photo by Bernard Hermant on Unsplash