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