SEE BELOW FOR THE ANSWER.
I remember solving this with an array formula a while back, but I haven't got the original workbook any more and the answer is completely escaping me.
Here's sample data:
Salesman Product
Bill Apple
Bob Orange
Bill Banana
Bob Apple
Bill Apple
Bob Orange
Bill Apple
What I'm wanting to do is make another table with the number of DISTINCT items Bob and Bill have sold. i.e:
Salesman Distinct Items
Bill 2
Bob 2
I remember using the array formula trick with IF
to build an array based on a lookup value, but for the life of me I can't figure out how I then applied a distinct count to that subsequent array. It was something to do with FREQUENCY
, but that only works with numbers and I haven't even been able to replicate that when I've tried just numbers. Here I've played around with both SUM(1/COUNTIF(RANGE,RANGE))
and SUMPRODUCT(1/COUNTIF(RANGE,RANGE))
.
Specifically, with Bill in D2
and Bob in D3
I've arrived at this array formula (placed in E2
and E3
):
{=SUM(IF($A$2:$A8=D2,1/COUNTIF($B$2:$B8,$B$2:$B8)))}
(D3 is obviously substituted for D2 in cell E3
.)
It's still way off, though. I'm using Evaluate Formula to trace it and I can see that the COUNTIF
counts all the occurrences of each item, not just the ones belonging to the lookup.
Any pointers back in the right direction? It's really frustrating given that I cracked it once in the past.
(I realise with Excel 2013 I can do it with Distinct Count
in a PivotTable, but I'm needing to do it outside of one here for a couple of reasons.)
Thanks in advance.
EDIT - FOUND IT - SEE ANSWER BELOW