Counting with Two Criteria

Written by Allen Wyatt (last updated April 7, 2018)
This tip applies to Excel 97, 2000, 2002, and 2003

John has a worksheet that contains records used in a cost-tracking system. Record numbers are entered in column A, locations in column B, and costs in column C. Not all records have a cost value entered in column C. John wants to determine a count of records "with location X and cost <> 0".

Your first impulse may be to use one of the worksheet functions designed for counting, such as CountIf. The only problem is that CountIf doesn't permit two conditions to be checked in calculating a solution. There are, however, a couple of solutions you can use, without the need of adding additional columns or intermediate calculations.

The first (and perhaps simplest) solution is to use the SUMPRODUCT worksheet function. This function allows you to count or sum data from a column, row, or array with as many criteria as you want. The basic syntax is as follows:


In this particular instance, you could put the formula together like this:


What this does is provide two different conditions that are checked. First, the cells in column B are checked to see if they equal "X", then the corresponding cells in column C are checked to see if they are equal to 0. Both conditions return either True (1) or False (0). These results are then multiplied by each other, resulting in either 1 or 0. The SUMPRODUCT function then adds them together, resulting in a cumulative count.

Another solution is to create an array formula that will do the calculation for you. Array formulas are different than regular formulas, in that they work on a number of cells, iterating through them to produce a result. Consider the following formula:


This returns a single value, either 1 or 0. The formula uses the same basic logic described in the earlier explanation of the SUMPRODUCT solution. The two logical comparisons return 1 or 0, which are multiplied by each other, resulting in 1 or 0 as an answer. Now, consider the following formula:


This now looks very much like the earlier SUMPRODUCT formula, but it will not work properly as a straight formula. This is because SUM is not designed to work in an iterative fashion on an range of cells. If you enter this formula as an array formula (press Shift+Ctrl+Enter to enter it), then Excel understands you want to work through each of the ranges, in turn, to figure the final sum, which is a count of records that meet the stated criteria.

The different ways you can use array formulas is quite a broad topic. For more information on how array formulas work, see other issues of WordTips, or refer to the following Web site:

A third option is to use the database worksheet functions to return a count. Using these, you set up a "criteria table" in your worksheet, and then the function uses the criteria to analyze the records. The following steps assume that the column labels for the three columns are RecNum, Location, and Cost:

  1. Find a few empty cells, either on the same worksheet as your records or on a different worksheet. (For the sake of this example, I assume you are using columns J and K.)
  2. In cell J1, enter the word Location.
  3. In cell K1, enter the word Cost.
  4. In cell J2, enter X.
  5. In cell K2, enter >0. You have now entered your criteria table in cells J1:K2.
  6. Select cells J1:K2.
  7. Choose Name from the Insert menu, then choose Define. Excel displays the Define Name dialog box. (See Figure 1.)
  8. Figure 1. The Define New Name dialog box.

  9. Enter the name Criteria, then click OK.
  10. In the cell where you want a count of records meeting your criteria, enter the following:

Notice that the first argument used with DCOUNT is the second and third columns of your records list. This argument also includes the column labels, which are necessary so that DCOUNT can locate the proper criteria matches from the criteria table (third argument).

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2815) applies to Microsoft Excel 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Changing the Office Assistant

The Office Assistant is part of the Help system available in Excel. If you want, you can change which Office Assistant ...

Discover More

Creating an Excel Workbook from within Word

Word and Excel are both programs within the Microsoft Office suite. If you use both of these programs often, you may ...

Discover More

Controlling Automatic Indenting

Type a tab character and you might just find that Word adjusts the indentation of the entire paragraph. If you don't like ...

Discover More

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!

More ExcelTips (menu)

Using the FORECAST Function

Excel provides a handy worksheet function that allows you to forecast values based upon a set of known values. This ...

Discover More

Median of Selected Numbers

Need to find a median value in a series of values? It's easy with the MEDIAN function. What isn't as easy is to derive ...

Discover More

Adding Up Tops and Bottoms

When you are working with sequenced values in a list, you'll often want to take some action based on the top X or bottom ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is six less than 9?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)

This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.