Count unique values with criteria

skitalez

New Member
Joined
Sep 6, 2007
Messages
16
Hi everyone,
I have a list of data, that goes like this:
Day Month Department Worker Sales
1 1.2015 Department 3 A 5
2 1.2015 Department 4 B 8
3 1.2015 Department 7 D 12
4 1.2015 Department 7 A 33
5 1.2015 Department 3 V 19
6 1.2015 Department 1 G 81
7 1.2015 Department 2 H 14
8 1.2015 Department 2 P 57
9 1.2015 Department 1 R 63
10 1.2015 Department 9 V 95
11 1.2015 Department 4 B 21
1 2.2015 Department 3 A 2
2 2.2015 Department 8 R 84
3 2.2015 Department 5 F 36
4 2.2015 Department 5 Q 64
5 2.2015 Department 10 W 66
6 2.2015 Department 8 F 46
7 3.2015 Department 10 H 32
8 3.2015 Department 1 R 19
9 3.2015 Department 1 Y 92
10 3.2015 Department 10 A 74
11 3.2015 Department 6 S 55
12 3.2015 Department 4 D 70
13 3.2015 Department 7 B 5

I'm trying to answer the question "how many different workers were in each month in each department?" in the following table (the same worker can work in different departments):
Dep/Month 1 .2015 2 .2015 3 .2015
Department 1
Department 2
Department 3
Department 4
Department 5
Department 6
Department 7
Department 8
Department 9
Department 10

Thanks for help!
 
Roger, thanks for Pivot Table option, I've tried it already.
The problem is that the count of "worker" field counts ALL workers from given departments and given months (counts all rows), not the unique workers.
Pivot table would be better decision, since it work fast compare to FREQUENCY array formula
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Aladin, I've just finish counting the data for 2015 months in PC with i7, 8 processors and 16 MB RAM.
On my PC, Excel just crashed...
 
Upvote 0
Thank you Aladin , it still works and gives the result. And I also will try to do Pivot on Pivot table according to Roger's advice
 
Upvote 0
Thank you Aladin , it still works and gives the result. And I also will try to do Pivot on Pivot table according to Roger's advice

Great. By all means, try the pivot procedure too. How about the VBA MickG has jotted down for you?

Here is an improvement on the formula approach...

Row\Col
A​
B​
C​
D​
E​
F​
I​
J​
K​
L​
1​
DayMonthDep#WorkerSalesconcatDep/Month
1.2015​
2.2015​
3.2015​
2​
1​
1.2015​
Dep#3A
5​
Dep#3|1.2015Dep#1
2​
0​
2​
3​
2​
1.2015​
Dep#4B
8​
Dep#4|1.2015Dep#2
2​
0​
0​
4​
3​
1.2015​
Dep#7D
12​
Dep#7|1.2015Dep#3
2​
1​
0​
5​
4​
1.2015​
Dep#7A
33​
Dep#7|1.2015Dep#4
1​
0​
1​
6​
5​
1.2015​
Dep#3V
19​
Dep#3|1.2015Dep#5
0​
2​
0​
7​
6​
1.2015​
Dep#1G
81​
Dep#1|1.2015Dep#6
0​
0​
1​
8​
7​
1.2015​
Dep#2H
14​
Dep#2|1.2015Dep#7
2​
0​
1​
9​
8​
1.2015​
Dep#2P
57​
Dep#2|1.2015Dep#8
0​
2​
0​
10​
9​
1.2015​
Dep#1R
63​
Dep#1|1.2015Dep#9
1​
0​
0​
11​
10​
1.2015​
Dep#9V
95​
Dep#9|1.2015Dep#10
0​
1​
2​
12​
11​
1.2015​
Dep#4B
21​
Dep#4|1.2015
13​
1​
2.2015​
Dep#3A
2​
Dep#3|2.2015
14​
2​
2.2015​
Dep#8R
84​
Dep#8|2.2015
15​
3​
2.2015​
Dep#5F
36​
Dep#5|2.2015
16​
4​
2.2015​
Dep#5Q
64​
Dep#5|2.2015
17​
5​
2.2015​
Dep#10W
66​
Dep#10|2.2015
18​
6​
2.2015​
Dep#8F
46​
Dep#8|2.2015
19​
7​
3.2015​
Dep#10H
32​
Dep#10|3.2015
20​
8​
3.2015​
Dep#1R
19​
Dep#1|3.2015
21​
9​
3.2015​
Dep#1Y
92​
Dep#1|3.2015
22​
10​
3.2015​
Dep#10A
74​
Dep#10|3.2015
23​
11​
3.2015​
Dep#6S
55​
Dep#6|3.2015
24​
12​
3.2015​
Dep#4D
70​
Dep#4|3.2015
25​
13​
3.2015​
Dep#7B
5​
Dep#7|3.2015

In F2 just enter and copy down:
Rich (BB code):

=C2&"|"&B2
<strike></strike>


In J2 control+shift+enter, not just enter, and copy down:
Rich (BB code):

=SUM(IF(FREQUENCY(IF($F$2:$F$25=$I2&"|"&J$1,MATCH($D$2:$D$25,$D$2:$D$25,0)),Ivec),1))

Ivec is defined in Name Manager as referring to:
Rich (BB code):

=ROW(Sheet1!$F$2:$F$25)-ROW(Sheet1!$F$2)+1

Adjust to suit.

Note. We are trading off memory against speed here.
 
Upvote 0
Aladin, tried both methods you've proposed - the result is the same in time that my Excel need to calculate each cell. Approx 30 seconds.
Tried pivot on pivot table, that Roger proposed link to.
Get confused in it, cause in pivot 1 I need to put Dep, month and worker in row labels. And when forming Pivot 2 I've tried different combinations of what field where to put, but it doesn't work.
I've also tried to put month in column labels but also with no result.
Haven't yet tried VBA that MickG offered...
 
Upvote 0
Roger, in downloadable example there is only one filter criteria - region. In my pivot there are two - dep and month. How it can be solved?
 
Upvote 0

Forum statistics

Threads
1,215,828
Messages
6,127,126
Members
449,361
Latest member
VBquery757

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