Countif Unique values only?

Mudbutt

Board Regular
Joined
Jul 18, 2011
Messages
158
I'm using Excel 2008. I have a production order # column that has duplicates in it. I also have a week num column with multiple weeks. I need to do a count on unique production order #'s by Week. I'm not sure how to do that.

I found this formula =SUM(IF(FREQUENCY(A2:A10,A2:A10)>0,1)) which would help me get the count for all the orders, but it doesn't get it to me by week. Can anyone help me add that criteria?
 
I'm using Excel 2008. I have a production order # column that has duplicates in it. I also have a week num column with multiple weeks. I need to do a count on unique production order #'s by Week. I'm not sure how to do that.

I found this formula =SUM(IF(FREQUENCY(A2:A10,A2:A10)>0,1)) which would help me get the count for all the orders, but it doesn't get it to me by week. Can anyone help me add that criteria?
Try this...

Book1
ABCDE
1Week NumOrder Num_Week NumUniques
21103_12
31105_22
42104_31
52104_41
62109_51
72109_60
83110_72
93110_81
104104_92
115101_101
127102___
137102___
147102___
157107___
168110___
179107___
189110___
1910103___
2010103___
Sheet1

This array formula** entered in E2 and copied down:

=SUM(IF(FREQUENCY(IF(A$2:A$20=D2,B$2:B$20),B$2:B$20),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
Hmm I'm just getting 0's for the uniques. Does it matter that in my week column it's text (i.e. "Week 35") instead of a number? Does that throw it off?
 
Upvote 0
Hmm I'm just getting 0's for the uniques. Does it matter that in my week column it's text (i.e. "Week 35") instead of a number? Does that throw it off?
It would make a difference if the order nums are text.

Try this...

Book1
ABCDE
1Week NumOrder Num_Week NumUniques
2Week 1103_Week 12
3Week 1105_Week 22
4Week 2104_Week 31
5Week 2104_Week 41
6Week 2109_Week 51
7Week 2109_Week 60
8Week 3110_Week 72
9Week 3110_Week 81
10Week 4104_Week 92
11Week 5101_Week 101
12Week 7102___
13Week 7102___
14Week 7102___
15Week 7107___
16Week 8110___
17Week 9107___
18Week 9110___
19Week 10103___
20Week 10103___
Sheet1

This array formula** entered in E2 and copied down:

=SUM(IF(FREQUENCY(IF(A$2:A$20=D2,MATCH(B$2:B$20,B$2:B$20,0)),ROW(B$2:B$20)-ROW(B$2)+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.
 
Upvote 0
Yeah, my order numbers are being stored as text. I'm still testing to see if your latest formula will work. It's taking forever for excel to process it because there are so many lines. It's been 10 minutes, so I'm not sure if it will work.
 
Upvote 0
Yeah, my order numbers are being stored as text. I'm still testing to see if your latest formula will work. It's taking forever for excel to process it because there are so many lines. It's been 10 minutes, so I'm not sure if it will work.
You might be better off using a pivot table.

I never use pivot tables so someone else will need to help get it set up. Try starting a new thread and use a subject line something like: Need Pivot Table to count unique items in large dataset. Maybe I'll even learn how to do it!
 
Upvote 0
I'll try, but so far i haven't been able to figure out how to count unique values in a pivot. This is a tough one.
 
Upvote 0
I'll try, but so far i haven't been able to figure out how to count unique values in a pivot. This is a tough one.
Hi,

Try adding an extra column to your dataset like this:

Sheet1[TABLE="class: html-maker-worksheet"]
<tbody>[TR]
[TH][/TH]
[TH]A[/TH]
[TH]B[/TH]
[TH]C[/TH]
[/TR]
[TR]
[TH]1[/TH]
[TD]Week Num[/TD]
[TD]Order Num[/TD]
[TD]WeekOrder[/TD]
[/TR]
[TR]
[TH]2[/TH]
[TD]Week 1[/TD]
[TD="align: right"]103[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]3[/TH]
[TD]Week 1[/TD]
[TD="align: right"]105[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]4[/TH]
[TD]Week 2[/TD]
[TD="align: right"]104[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]5[/TH]
[TD]Week 2[/TD]
[TD="align: right"]104[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TH]6[/TH]
[TD]Week 2[/TD]
[TD="align: right"]109[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]7[/TH]
[TD]Week 2[/TD]
[TD="align: right"]109[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TH]8[/TH]
[TD]Week 3[/TD]
[TD="align: right"]110[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]9[/TH]
[TD]Week 3[/TD]
[TD="align: right"]110[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TH]10[/TH]
[TD]Week 4[/TD]
[TD="align: right"]104[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]11[/TH]
[TD]Week 5[/TD]
[TD="align: right"]101[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]12[/TH]
[TD]Week 7[/TD]
[TD="align: right"]102[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]13[/TH]
[TD]Week 7[/TD]
[TD="align: right"]102[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TH]14[/TH]
[TD]Week 7[/TD]
[TD="align: right"]102[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TH]15[/TH]
[TD]Week 7[/TD]
[TD="align: right"]107[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]16[/TH]
[TD]Week 8[/TD]
[TD="align: right"]110[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]17[/TH]
[TD]Week 9[/TD]
[TD="align: right"]107[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]18[/TH]
[TD]Week 9[/TD]
[TD="align: right"]110[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]19[/TH]
[TD]Week 10[/TD]
[TD="align: right"]103[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TH]20[/TH]
[TD]Week 10[/TD]
[TD="align: right"]103[/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]
Excel 2010

CellFormula
C2=N(NOT(SUMPRODUCT(--($A$2:$A2=A2),--($B$2:$B2=B2))>1))

<tbody>
[TD="bgcolor: #FFFFFF"] Worksheet Formulas [TABLE="class: html-maker-worksheet"]
<tbody>[TR]

</tbody>
[/TD]
[/TR]
</tbody>[/TABLE]

  • Now create a PivotTable and the new helper column can be used for the unique count. There is a nice article that describes the technique here:
  • SUMIF/SUMIFS combinations may be faster than SUMPRODUCT.
  • As an alternatively to the PivotTable you can ofcourse also use a formula solution with the helper column using SUMIF/SUMIFS as appropriate.
  • I'm not sure if your version of Excel supports VBA, but if it does then an efficient unique count UDF solution is presented in this very useful whitepaper by Charles Williams (you would need to tweak it a little bit to account for your extra column):
 
Last edited:
Upvote 0

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