Count unique values based on criteria

leterrier

New Member
Joined
Jan 5, 2013
Messages
44
Dear Friends,


I have two columns of sales data A and B. Column A contains garment types e.g. Hats, Coats, Scarves etc. and each entry is unique. Column B contains colours e.g. green, red, blue etc. and contains duplicates (and possibly blanks). I wish to know how many different coloured hats have been purchased. Having trawled the web, the common result on a question like this provides a formula structured:

=SUMPRODUCT((Criteria_Range="Hats")/COUNTIF(Count_Range , Count_Range&""))

When I apply this formula, I keep getting answers there not whole numbers e.g. 1.5 or 0.8. My query cannot be that complicated, what am I doing wrong?

Can someone help? Its driving me crazy. Thank you!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try using this "array formula"

=SUM(IF(FREQUENCY(IF(Criteria_Range="Hats",IF(Count_Range<>"",MATCH(Count_Range,Count_Range,0))),ROW(Count_Range)-MIN(ROW(Count_Range))),1))

confirmed with CTRL+SHIFT+ENTER
 
Upvote 0
Barry, Thanks again, I have tried this and I get a #value! return. I note also that despite my using ctrl+shift+enter, I see no braces around the [array] formula?

Try using this "array formula"

=SUM(IF(FREQUENCY(IF(Criteria_Range="Hats",IF(Count_Range<>"",MATCH(Count_Range,Count_Range,0))),ROW(Count_Range)-MIN(ROW(Count_Range))),1))

confirmed with CTRL+SHIFT+ENTER
 
Upvote 0
Sales Data
Garment (A)
Colour (B)
hatsred
coatsgreen
scarvesblue
hatsgreen
coatsred
scarvesblue
hatsred
coatsgreen
Hats blank
scarvesred
I wish to know how many different coloured hats have been sold, the answer is 2 (red and green)
The formula I need is: if the criteria in column A is "hats",
how many unique values are in column B - excluding blanks? The answer is 2 (red and green)
<colgroup><col width="107" style="width: 80pt; mso-width-source: userset; mso-width-alt: 3913;"> <col width="113" style="width: 85pt; mso-width-source: userset; mso-width-alt: 4132;"> <col width="64" style="width: 48pt;" span="6"> <tbody> </tbody>
 
Upvote 0
I have tried this and I get a #value! return. I note also that despite my using ctrl+shift+enter, I see no braces around the [array] formula?

To "array enter" correctly do this:

Select cell with formula and press F2 key to select formula
Hold down CTRL and SHIFT keys while pressing ENTER
You should now see { and } around the formula and get a numeric result
 
Upvote 0
Barry, Thank you. Its now working perfectly!! Excellent...

To "array enter" correctly do this:

Select cell with formula and press F2 key to select formula
Hold down CTRL and SHIFT keys while pressing ENTER
You should now see { and } around the formula and get a numeric result
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top