Distinct Count Based on Multiple Criteria

kparadise

Board Regular
Joined
Aug 13, 2015
Messages
186
Hello,

I am building a tab [results]; on this tab, I have a column [column A] which lists a unique value (description). In [column B]; I need to create a formula. This formula needs to look into the [raw data] tab, and count the number of distinct IDs which share the same (description) and also have one more criteria with color = "red".

[results]
A
B
1
description
test
2
Tiny Shoes
NEED FORMULA HERE; 1
3
Small Shoes
2
4
Tiny Socks
0
5
Small Socks
0
6
Tiny Shirt
1
7
Small Shirt
0

<tbody>
</tbody>

[raw data]
A
B
C
D
1
ID
Color
description
2
aaa
red
Tiny Shoes
3
aaa
red
Tiny Shoes
4
aaa
blue
Tiny Shoes
5
aaa
red
Small Shoes
6
aaa
red
Tiny Shirt
7
bbb
blue
Tiny Shirt
8
bbb
blue
Tiny Shirt
9
bbb
red
Small Shoes

<tbody>
</tbody>

So basically, I want to look up [results].A2 in [raw data].C:C, make sure we are only looking at the "red" values in [raw data].B:B; and then count the number of distinct IDs associated with those two criteria.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try

A
B
C
1
description​
test​
Criteria​
2
Tiny Shoes​
1​
red​
3
Small Shoes​
2​
4
Tiny Socks​
0​
5
Small Socks​
0​
6
Tiny Shirt​
1​
7
Small Shirt​
0​

Array formula in B2 copied down
=SUM(IF(FREQUENCY(IF('RAW DATA'!C$2:C$100=A2,IF('RAW DATA'!B$2:B$100=C$2,MATCH('RAW DATA'!A$2:A$100,'RAW DATA'!A$2:A$100,0))),ROW('RAW DATA'!A$2:A$100)-ROW('RAW DATA'!A$2)+1),1))
confirmed with Ctrl+Shift+Enter, not just Enter

M.
 
Upvote 0
2013 = you have a new column C entered there. I do not have that. How would that change the formula if you made it "red" instead for referencing a cell?
 
Last edited:
Upvote 0
Yea, it is not working. Getting #N/A now; but I can view in the raw data tab the number I need it to return; by simply filtering.


Code:
{=SUM(IF(FREQUENCY(IF(combinedCCB2018!G$2:G$2423=A2,IF(combinedCCB2018!C$2:C$2423="Testing", MATCH(combinedCCB2018!B$2:B$2423,combinedCCB2018!B$2:B$2423,0))),ROW(combinedCCB2018!B$2:B$2423)-ROW(combinedCCB2018!B$2)+1),1))}
 
Last edited:
Upvote 0
Yea, it is not working. Getting #N/A now; but I can view in the raw data tab the number I need it to return; by simply filtering.

Worked for me
Array formula
=SUM(IF(FREQUENCY(IF('RAW DATA'!C$2:C$100=A2,IF('RAW DATA'!B$2:B$100="Red",MATCH('RAW DATA'!A$2:A$100,'RAW DATA'!A$2:A$100,0))),ROW('RAW DATA'!A$2:A$100)-ROW('RAW DATA'!A$2)+1),1))
confirmed with Ctrl+Shift+Enter

Could you show the formula you are using?

M.
 
Upvote 0
See Above.

Are you using exactly the formula above (post 8)?

If so, it should have worked for you, provided (check):
The sheet name is exactly RAW DATA
The data are in columns A:C beginning at row 2; headers on row 1 (like your data sample in post 1)
There are no errors in any cell

M.
 
Upvote 0

Forum statistics

Threads
1,214,625
Messages
6,120,598
Members
448,973
Latest member
ksonnia

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