SOLVED

# counting unique values after multiple filters

Occasional Contributor

# counting unique values after multiple filters

I've found many examples that come really close to what I need, but not quite right... I need to count how many unique locations contain a part after doing multiple filters for the specific part. I've tried many combinations of count, if, sum, unique, filter, etc. Can't quite get there.

Assume I do a database dump on the first day of the month showing all parts in all locations. One of the summary points for my monthly report is to drill down to a very specific part, in a specific state, and count how many locations are being used (consumed!) by that part.

Here is a really simplified example:

I want a count, a single integer number, of unique locations are being used by light red parts in a state of "return". (If my data were this neat, I could do a pivot table with appropriate filters, but it isn't. I need to use some LEFT or IF functions to pull out key text to get the correct matches. I've got a)

The correct answer for "how many locations are being consumed by light red parts in a state of return" is two. Two locations are being used by those returned goods.

I'm running with a 365 subscription. I think COUNTA, UNIQUE and two or three FILTERS should get my number, but so far, no luck!

3 Replies

# Re: counting unique values after multiple filters

Enter red in G2, light in H2 and return in I2.

Formula in J2:

=SUM(--(LEN(UNIQUE(FILTER(Table1[location],(Table1[part]=G2)*(Table1[variety]=H2)*(Table1[state]=I2),"")))>0))

See the attached version.

It would also be possible to use a pivot table for this (you have to add the source range to the Data Model)

# Re: counting unique values after multiple filters

Thanks! This looks really helpful. Still struggling a bit using wild cards. Say if I needed to use "retu*" in place of your using cell I2 containing the word "return". That seems to break something. But I'm pretty sure I'll get around that. Thanks again, this was hugely helpful!
best response confirmed by Brian_Paasch (Occasional Contributor)
Solution

# Re: counting unique values after multiple filters

Got it! I have multiple variations of the "return" state. BUT, they all start with the word "return". So I added a LEFT to that last step, i.e. LEFT(Table1[state],6)="return"), and that did the trick! Thanks again!