excelmatchuniquecountifwhitelist

Counting number of unique values in one column if data in a 2nd column matches anything in a 3rd column


I have data that will be changing daily. I'd simply like to get a count of unique values from the first column if the data in the same row of the 2nd column matches anything in the 3rd column located elsewhere. For the most part the 3rd column to the side will stay the same and will be like an external whitelist and the first 2 columns will change daily. I'd like to do this with a formula and not using the drop down filters

Example

For example, there are 3 possible locations in this. I want a count of how many locations (1, 2, or 3) that the desired colored product is found in.

Home contains both red and pink from the desired list. Car contains only red from the desired list. Even though there are 8 lines with the correct color or multiple colors for each location, I only want to know how many different locations contain those colors. In this case the answer should come back as 2.

I've tried multiple combinations of countif/index/match/etc but I have not figured out the proper way to do it. Also this will be used in Excel 2016.


Solution

  • For Excel 2016 you would be looking at this method of doing unique counts. In your case you could use Countif to check that a colour appears in the list and then (since the locations are strings) use match to convert them into numbers as shown in the second example in the reference.

    =SUM(--(FREQUENCY(IF(COUNTIF(Table2[Color],Table1[Products]),MATCH(Table1[Locations],Table1[Locations],0)),MATCH(Table1[Locations],Table1[Locations],0))>0))
    

    enter image description here

    As noted this should be confirmed with CtrlShiftEnter or you could use Sumproduct rather than Sum.