Count of unique values with multiple criteria

mikechambers

Active Member
Joined
Apr 27, 2006
Messages
397
I am trying to get a unique count of dates in one column if another column matches a number. So....

918 7/18/11
918 7/18/11
917 7/22/11
915 7/21/11
918 7/19/11
919 7/21/11
916 7/18/11
918 7/20/11
919 7/19/11

So for example, Column B shows 5 different dates all together. But I want to count how many different dates (unique values) there are if Column A has 918, which should result in 3. Does that make sense? I was playing around with the Frequency function, and had so far:

=SUM(IF(FREQUENCY(B1:B9,B1:B9)>0,1))

This gives me 5, which is the number of unique entries in Column B. Any ideas how I could tweak this?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I am trying to get a unique count of dates in one column if another column matches a number. So....

918 7/18/11
918 7/18/11
917 7/22/11
915 7/21/11
918 7/19/11
919 7/21/11
916 7/18/11
918 7/20/11
919 7/19/11

So for example, Column B shows 5 different dates all together. But I want to count how many different dates (unique values) there are if Column A has 918, which should result in 3. Does that make sense? I was playing around with the Frequency function, and had so far:

=SUM(IF(FREQUENCY(B1:B9,B1:B9)>0,1))

This gives me 5, which is the number of unique entries in Column B. Any ideas how I could tweak this?
Try this...

Array entered**:

=SUM(IF(FREQUENCY(IF(A2:A10=918,B2:B10),B2:B10),1))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0
So is there any reason this would not work with text fields? I used it for the one instance with the dates and it worked fine. But now I'm trying it in another spreatsheet, where instead of dates I am trying to find the number of unique names and it's coming back 0 everytime. And I did the CSE.
 
Upvote 0
OK I just went into Help and saw that Frequency ignores Text. So is there another way to do this same thing with text?
 
Upvote 0
So is there any reason this would not work with text fields? I used it for the one instance with the dates and it worked fine. But now I'm trying it in another spreatsheet, where instead of dates I am trying to find the number of unique names and it's coming back 0 everytime. And I did the CSE.
Counting unique text entries is a bit more complicated.

Book1
ABC
29187/18/2011text1
39187/18/2011text1
49177/22/2011text1
59157/21/2011text2
69187/19/2011text3
79197/21/2011text3
89167/18/2011text3
99187/20/2011text3
109197/19/2011text4
Sheet2

Count the unique text in column C if column A = 918.

Array entered**:

=SUM(IF(FREQUENCY(IF(A2:A10=918,MATCH(C2:C10,C2:C10,0)),ROW(C2:C10)-ROW(C2)+1),1))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Assumes no empty cells within the data range of column C.
 
Upvote 0
Once again, Awesome!! Thank you!!!

One question though. I am copying this down to determine the counts for different numbers (918, 919, 920, etc) so obviously I have a cell reference in place of the 918 that's hard coded. So I also then have all of the ranges in your formula locked both col and row. So what does the ROW(C2) do exactly? Wouldn't that always be a hard 2?
 
Upvote 0
Once again, Awesome!! Thank you!!!

One question though. I am copying this down to determine the counts for different numbers (918, 919, 920, etc) so obviously I have a cell reference in place of the 918 that's hard coded. So I also then have all of the ranges in your formula locked both col and row. So what does the ROW(C2) do exactly? Wouldn't that always be a hard 2?
MATCH returns an array of numbers from 1 to n.

The frequency bins also have to be an array of numbers that correspond to the array returned by MATCH. We use the ROW function to generate the bins.

If the range is C2:C10, a total of 9 cells, then MATCH will return an array of numbers from 1 to 9. Using the ROW function we have to generate the bins array from 1 to 9. Here's how we do that:

ROW(C2:C10)-ROW(C2)+1

ROW(C2)-ROW(C2)+1 = (2)-(2)+1 = 1
ROW(C3)-ROW(C2)+1 = (3)-(2)+1 = 2
ROW(C4)-ROW(C2)+1 = (4)-(2)+1 = 3
ROW(C5)-ROW(C2)+1 = (5)-(2)+1 = 4
ROW(C6)-ROW(C2)+1 = (6)-(2)+1 = 5
...
...
ROW(C10)-ROW(C2)+1 = (10)-(2)+1 = 9
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,503
Members
452,917
Latest member
MrsMSalt

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