Reputation: 3
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
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.
Upvotes: -3
Views: 117
Reputation: 34370
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))
As noted this should be confirmed with CtrlShiftEnter or you could use Sumproduct rather than Sum.
Upvotes: 1
Reputation: 353
Since you're on 2016, I suggest you break down your process into separate columns. That should make this both maintainable and clear.
I've put your data into two Excel Tables: Flags and Data. That saves you from filling an unpredictable number of rows with your formulas.
Flags | MatchData | Labels | Values | MatchFlag | CountFlagMatches | ||
---|---|---|---|---|---|---|---|
red | TRUE | home | red | red | 2 | ||
pink | TRUE | home | red | red | |||
yellow | home | blue | |||||
green | home | blue | |||||
home | pink | pink | |||||
home | pink | pink | |||||
work | blue | ||||||
work | blue | ||||||
car | blue | ||||||
car | blue | ||||||
car | red | red | |||||
car | red | red |
MatchData:
=IFNA(IF(VLOOKUP([@Flags], Data[MatchFlag], 1, FALSE)<>"", TRUE, FALSE), "")
MatchFlags:
=IFNA(VLOOKUP([@Values], Flags[Flags], 1, FALSE), "")
CountFlagMatches:
=COUNTIF(Flags[MatchData], "=TRUE")
Upvotes: 0