MicrosoftВ® Office ExcelВ® 2007: Data Analysis and Business Modeling (Bpg -- Other)

Overview

We often want to count the number of cells in a range that meet a given criterion. For example, if a worksheet contains information about makeup sales, we might want to count the number of sales transactions made by the salesperson named Jennifer, or the number of sales transactions that occurred after June 10. The COUNTIF function lets you count the number of cells in a range that meet criteria that are defined on the basis of a one row or column of the worksheet.

The syntax of the COUNTIF function is COUNTIF(range,criterion).

The syntax of COUNTIFS (new in Microsoft Office Excel 2007) is COUNTIFS(range1, criterion1,range2,criterion2,…,range_n,criterion_n).

COUNTIFS will count the number of rows for which the range1 entry meets criterion1, the range2 entry meets criterion2, the range_n entry meets criterion_n, and so on. Thus, COUNTIFS allows the criteria to involve more than one column or multiple conditions in one column. Other functions that allow for multiple criteria are discussed in Chapter 19, “The SUMIF, AVERAGEIF, SUMIFS, and AVERAGEIFS Functions,” and Chapter 39, “Summarizing Data with Database Statisitical Functions.”

The key to using the COUNTIF function (and other similar functions) successfully is understanding the wide variety of criteria that Excel will accept. The types of criteria you can use are best explained through the use of examples. In addition to examples of the COUNTIF function, I’ll provide examples of the COUNT, COUNTA, and COUNTBLANK functions:

As an illustration of how to use these functions, consider a database that gives the following information for each song played on radio station WKRP:

The file Rock.xlsx, shown in Figure 18-1, shows a subset of the data.

Figure 18-1: The song database we use for the COUNTIF examples

Категории