Search code examples
countunique

Google Sheets: Count of unique items, considering two criterias


I'm looking for a simple way to count unique items based on two criterias. I tried it by myself with various combinations of Arrayformula, Countif, Query, Countuniqueifs and/or Filter, but couldn't make it work.

The example.

I have a list of different IDs (with some gaps in between) in column A and an criteria in column B. The logic I want to have applied is: Sum of all unique IDs, except of 'empty', which have bought=yes.

In the example the following IDs would be legit and have bought=yes: Apple (row 2) Juice (row 5) Kiwi (row 9) Pear (row 12)

So the result should be: 4

Does anyone have a convenient solution?


Solution

  • I am sure there are many ways to solve this, I used the QUERY() and UNIQUE() functions

    =query(UNIQUE(A1:B13); "SELECT COUNT(Col1) WHERE Col2 = 'yes' LABEL COUNT(Col1) ''"; 1)
    

    enter image description here