Home > OS >  Correct Way To "COUNTUNIQUE" That Only Counts Once
Correct Way To "COUNTUNIQUE" That Only Counts Once

Time:10-10

I am trying to count the unique values of a column, based on their status in another column, example:

Customers License Active
Adam Yes
Barry No
Adam No
Claire No

In this situation, I want to know how many customers have at least 1 active license, and how many customers do not have at least one active license.

The formula I have tried is: =COUNTUNIQUEIFS(A2:A,B2:B,"Yes") This returns 1 in this situation which is correct, as there is 1 customer who has a Yes on column B. My issue is when I try to do the reverse, count the "No" using this formula: =COUNTUNIQUEIFS(A2:A,B2:B,"No") it returns 3 which is not the desired result as it is counting the second Adam as a unique value too because they have a "No" in column B.

The result I want here is 2, because Adam has a yes somewhere in column B so I don't want him counted again the next time his field is counted.

CodePudding user response:

It seems to me that the easiest way to get the "No" count is like this:

=COUNTUNIQUE(A2:A)-COUNTUNIQUEIFS(A2:A,B2:B,"Yes")

It's even easier if you've already pulled the "Yes" count to a cell (say, C2), in which case the "No" count could be gained quite simply with this:

=COUNTUNIQUE(A2:A)-C2

CodePudding user response:

I don't think you can do it in a single step - try filtering out those with at least one "Yes" like this:

=countunique(filter(A2:A,countifs(B2:B,"Yes",A2:A,A2:A)=0))

enter image description here

  • Related