简体   繁体   中英

Counting unique values in a column that matches multiple criteria in a single column

I'm trying to count how many values in column A multiple multiple criteria that are mixed in column B. I was able to do this using a helper column (column C). To better get the idea, please see below:

   Row    Column A         Column B        Column C
          Day              Shift           Helper 

    1     Monday           Worked AM       Worked PM
    2     Tuesday          Worked AM    
    3     Wednesday        Worked AM       Worked PM
    4     Monday           Worked PM    
    5     Wednesday        Worked PM    

Column A contains days from Monday to Wednesday, column B contains shifts while column C contains a formula to return "Worked PM" if that day also has a "Worked PM" somewhere below. Basically, Monday and Wednesday has these in rows 4 and 5.

Formula for cell C1 is =IF(B1="Worked PM","",IF(COUNTIFS($A$1:$A$5,$A1,$B$1:$B$5,"Worked PM")>0,"Worked PM",""))

The reason why I have this helper column is because I want to count the days that have both "Worked AM" and "Worked PM" on them. In our example, the count formula should return 2. I used the following formula, which is working perfectly: =COUNTIFS($B$1:$B$5,"Worked AM",$C$1:$C$5,"Worked PM")

However, I wish to completely eliminate the helper column (column C), which I have failed to do ever since. I tried making use of SUMPRODUCT, COUNT+MATCH and COUNTIFS . I've seen tutorials on how to do this from different Excel help sites, but I've seen nothing that matched my concern. They were "close" (not sure), but when I reconfigure them, I always fail.

I've turned to here as my last stop before giving up. I want to ask if what I'm actually doing is impossible. If it is possible, I would as well seek your guidance on how can I arrive on the solution. Thanks in advance! :)

This will replicate the results from your helper column method. Enter as an array formula ( ctrl + shift + enter ):

=SUM(--IF(B2:B6="Worked AM",IFERROR(MATCH(A2:A6,IF(B2:B6="Worked PM",A2:A6),0),0)>0))

But unless you have duplicate row entries, wouldn't the count simply equal the number of repeats you have in column A? You don't have to enter this as an array formula:

=SUM(--(FREQUENCY(MATCH(A2:A6,A2:A6),ROW(A2:A6)-ROW(A2)+1)>1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM