Wednesday 25 September 2019

Excel count unique values if second criteria is also satisfied


I currently have a formula to count all unique values of a range, however I would like to expand this count all unique values, if a second column meets a second requirement, for example.


      A        B
1 Name Location
2 Tim Onsite
3 Tim Onsite
4 Ben Offsite
5 Lisa Onsite

In this instance the unique values of Name will return 3, for that I am using


=SUMPRODUCT(1/COUNTIF(A2:A5,A2:A5&""))

However when I try to use a COUNTIFS it always returns an error.


=SUMPRODUCT(1/COUNTIFS(A2:A5,A2:A5&"", B2:B5, "Onsite"))

Any ideas how to achieve this, so from my sample data, counting Onsite would return 2, (3 unique values, 2 of them satisfying the onsite criteria)



Answer



You need a bit more conversion:


=SUM(IFERROR(1/COUNTIFS(A2:A5,A2:A5&"", B2:B5, "Onsite"),0))


This is an array formula, so after inserting you need to press CTRL + SHIFT + ENTER


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...