How do I Count Unique Values With Conditions?

Scrambler307

New Member
Joined
Dec 23, 2011
Messages
4
I need to count unique values using conditions. I believe I need an aray formula. Can anyone help me? Here is my data. It has blanks and text in the columns. I need to count "Job type" by unique "Job Number".
The answer I am looking for should look like this.

ANSWER
A = 3
P = 4
J = 1
V = 1
E = 1

RAW DATA
A B
Job_Type Job_Number
A 2011-0161
A 2011-0107
P 1991-341A
P 1991-341A

P 1991-341A

J 2011-588A

P 2007-0001

P 2011-0118
A 2011-0157
A 2011-0157
P 1991-341A
P 2011-0008

P 2011-0118
E 2011-0001
V 2011-0001
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi

Here's one way:
<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="font-weight: bold;;">Job_Type</td><td style="font-weight: bold;;">Job_Number</td><td style="font-weight: bold;text-align: right;;"></td><td style="font-weight: bold;text-align: right;;"></td><td style="font-weight: bold;;">Unique Job types</td><td style="font-weight: bold;text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style=";">A</td><td style=";">2011-0161</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">A</td><td style="text-align: right;;">3</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style=";">A</td><td style=";">2011-0107</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">P</td><td style="text-align: right;;">4</td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style=";">P</td><td style=";">1991-341A</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">J</td><td style="text-align: right;;">1</td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style=";">P</td><td style=";">1991-341A</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">V</td><td style="text-align: right;;">1</td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style=";">P</td><td style=";">1991-341A</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">E</td><td style="text-align: right;;">1</td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style=";">J</td><td style=";">2011-588A</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style=";">P</td><td style=";">2007-0001</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style=";">P</td><td style=";">2011-0118</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style=";">A</td><td style=";">2011-0157</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">11</td><td style=";">A</td><td style=";">2011-0157</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">12</td><td style=";">P</td><td style=";">1991-341A</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">13</td><td style=";">P</td><td style=";">2011-0008</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">14</td><td style=";">P</td><td style=";">2011-0118</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">15</td><td style=";">E</td><td style=";">2011-0001</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">16</td><td style=";">V</td><td style=";">2011-0001</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet2</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Array Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style=" background-color: #E0E0F0;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">F2</th><td style="text-align:left">{=SUM(<font color="Blue">IF(<font color="Red">FREQUENCY(<font color="Green">IF(<font color="Purple">$A$2:$A$16=E2,MATCH(<font color="Teal">$B$2:$B$16,$B$2:$B$16,0</font>)</font>),MATCH(<font color="Purple">$B$2:$B$16,$B$2:$B$16,0</font>)</font>)>0,1</font>)</font>)}</td></tr></tbody></table><b>Entered with Ctrl+Shift+Enter.</b> If entered correctly, Excel will surround with curly braces {}.
<b>Note: Do not try and enter the {} manually yourself</b></td></tr></table><br />
 
Upvote 0
If you amend it to the following it should work:

{=SUM(IF(FREQUENCY(IF($A$2:$A$16=E2,MATCH($B$2:$B$16&"",$B$2:$B$16&"",0)),MATCH($B$2:$B$16&"",$B$2:$B$16&"",0))>0,1))}

amendments are in red
 
Upvote 0
I need to count unique values using conditions. I believe I need an aray formula. Can anyone help me? Here is my data. It has blanks and text in the columns. I need to count "Job type" by unique "Job Number".
The answer I am looking for should look like this.

ANSWER
A = 3
P = 4
J = 1
V = 1
E = 1

RAW DATA
A B
Job_Type Job_Number
A 2011-0161
A 2011-0107
P 1991-341A
P 1991-341A

P 1991-341A

J 2011-588A

P 2007-0001

P 2011-0118
A 2011-0157
A 2011-0157
P 1991-341A
P 2011-0008

P 2011-0118
E 2011-0001
V 2011-0001
With...

E2: A
E3: P
etc.

Control+shift+enter, not just enter, and copy down:
Rich (BB code):
=SUM(IF(FREQUENCY(IF($B$2:$B$100<>"",
  IF($A$2:$A$100=E2,MATCH("~"&$B$2:$B$100,$B$2:$B$100&"",0))),
   ROW($B$2:$B$100)-ROW($B$2)+1),1))

If there are no special meaning chars like < around the target entries, the "~"& and &"" bits can be removed from the formula.
 
Upvote 0
I need to count unique values using conditions. I believe I need an aray formula. Can anyone help me? Here is my data. It has blanks and text in the columns. I need to count "Job type" by unique "Job Number".
The answer I am looking for should look like this.

ANSWER
A = 3
P = 4
J = 1
V = 1
E = 1

RAW DATA
A B
Job_Type Job_Number
A 2011-0161
A 2011-0107
P 1991-341A
P 1991-341A

P 1991-341A

J 2011-588A

P 2007-0001

P 2011-0118
A 2011-0157
A 2011-0157
P 1991-341A
P 2011-0008

P 2011-0118
E 2011-0001
V 2011-0001
Try this...

Book1
ABCDE
2A2011-0161_A3
3A2011-0107_P4
4P1991-341A_J1
5P1991-341A_V1
6___E1
7P1991-341A___
8_____
9J2011-588A___
10_____
11P2007-0001___
12_____
13P2011-0118___
14A2011-0157___
15A2011-0157___
16P1991-341A___
17P2011-0008___
18_____
19P2011-0118___
20E2011-0001___
21V2011-0001___
22_____
23_____
24_____
25_____
Sheet4

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

=SUM(IF(FREQUENCY(IF(B$2:B$25<>"",IF(A$2:A$25=D2,MATCH(B$2:B$25,B$2:B$25,0))),ROW(B$2:B$25)-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
Aladin and Biff - thanks. Both your solutions are much better than mine because they avoid the repeated call to MATCH. I'll bear than in mind for the future :)
 
Upvote 0
I re-wrote some of th formula to make it work across several worksheets within the workbook and I had no problems. I processed a ton of data, Thanks. Lastly, and I dont know if this is possible, can anyone explain the science behind the aray formula so I can write my own? Is there a trick to writing these?
Thanks a bunch!
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

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