Hack 68 Count Only One Instance of Each Entry in a List

   

figs/moderate.gif figs/hack68.gif

When you have a large list of items, you might want to perform a count on the items without counting entries that appear multiple times. With this hack, you can count each unique entry only once .

Consider the list in Figure 6-10, which has been sorted so that you can see multiple entries easily.

Figure 6-10. Range of sorted names
figs/exhk_0610.gif

A normal count on this list (using COUNTA ) would result in the names Bill W, Dave H, Fran T, Frank W, and Mary O being counted more that once. The DCOUNTA function offers an alternative that is very efficient and easy to modify.

The syntax of the DCOUNTA function is as follows :

 DCOUNTA(database,field,criteria), 

The arguments for this function are the same as those for the DSUM function described in [Hack #65])


Building on the preceding list, in cell D1 enter the word Criteria (or any heading that is not the same as the field or column heading). Below this, in cell D2, enter this formula:

 =COUNTIF($A:A2,A2)=1 

Note the combination of relative (A2) references and absolute ($A$2) references! These are vital to the criteria working.

Now, in the cell where you want your result shown, enter this function:

 =DCOUNTA($A:$A0,1,$D:$D) 

This will use the criteria to exclude duplicates and give you the result you need, which is 11, as there are 11 unique names.



Excel Hacks
Excel Hacks: Tips & Tools for Streamlining Your Spreadsheets
ISBN: 0596528345
EAN: 2147483647
Year: 2003
Pages: 136

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net