Multiple criteria Unique Counting

barkley

Board Regular
Joined
Mar 31, 2003
Messages
148
I have a data sheet of four columns.
The first two columns are used in an array on my summary sheet. Column A contains the column headings, column B contains the row headings of this array.
I need to use some form of COUNTIF or SUMPRODUCT to count the unique entries in column C for each combination of Column A & B on the data sheet.
So far on my summary sheet I have
=SUMPRODUCT((Data!A3:A20000=B3)*(Data!B3:B20000=A4),(Data!D3:D20000))
Which seems to return 0 and wouldn't account for unique references only anyway.
Does this make sense to anyone & can you help?
Thanks.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Almost, except I need to use the second option on this post - other people will be accessing this report without the morefunc add-in.
I can't get the formula in the second option to work with my code.
My data is as follows:
Contractor and WO Count by Branch.xls
ABCD
1
2
3ABBEQUIPJohn2168160
4ABBEQUIPJune2218810
5ABBEQUIPJohn2153460
6ABBEQUIPHarry2159697
7ABBEQUIPEthel2161120
8ABBEQUIPHarry2166525
9ABBEQUIPJohn2166525
10ABBEQUIPTed2166525
11ABBLDMNTFred2109684
12ABBLDMNTBill2109685
13ABBLDREPIvor2132688
14ABBLDREPJohn2159725
15ABBLDREPJune2160488
16ABBLDREPJune2160488
17ABBLDREPJune2160488
18ABBLDREPBetty2160488
Data


My summary sheet is like this:
Contractor and WO Count by Branch.xls
ABCDE
1
2
3ABBABN
4BEQUIPName00
5BEQUIPNumber
6BLDMNTName
7BLDMNTNumber
8BLDREPName
9BLDREPNumber
10CASHName
11CASHNumber
Summary


As you can see, I have tried the SUMPRODUCT option (D4), but am not sure how to alter the other thread's option (C4).

Any help/time spent on this is appreciated.
 
Upvote 0
In your sumproduct forrmula, change the comma to an asterisk prior to the column C bit -- your column C data in non-numeric, and must be coerced into 0/1 by * rather than the native syntax of "," --

as in =SUMPRODUCT((....*(Data!C3

have to work, but will try to post back w/ more.
 
Upvote 0
It would have been helpful if you also provided the expected outcomes...
Book16
ABCDEF
1
2
3ABBABN
4BEQUIPName500
5BEQUIPNumber600
6BLDMNTName200
7BLDMNTNumber200
8BLDREPName400
9BLDREPNumber300
10CASHName000
11CASHNumber000
12
Summary


Formulas...

C4, which is copied across:

=SUM(IF(FREQUENCY(IF((Data!$A$3:$A$18=C$3)*(Data!$B$3:$B$18=$A4),MATCH(Data!$C$3:$C$18,Data!$C$3:$C$18,0),""),IF((Data!$A$3:$A$18=C$3)*(Data!$B$3:$B$18=$A4),MATCH(Data!$C$3:$C$18,Data!$C$3:$C$18,0),""))>0,1))

D4, which is also copied across:

=SUM(IF(FREQUENCY(IF((Data!$A$3:$A$18=C$3)*(Data!$B$3:$B$18=$A4),Data!$D$3:$D$18),IF((Data!$A$3:$A$18=C$3)*(Data!$B$3:$B$18=$A4),Data!$D$3:$D$18))>0,1))

Both formulas need to be confirmed with control+shift+enter, not just with enter.

Select C4:E5 and copy down.
 
Upvote 0
Thanks for the help it is now working well.
I can understand that for 20,000 rows it will take some time to compute the formulas (my summary array is approx 80 x 30 cells)
I think I'll leave my computer running over the weekend & hope that by Monday morning all the figures are there!
Still, its a darn sight quicker than me calculating it manually!
 
Upvote 0
barkley said:
Thanks for the help it is now working well.
I can understand that for 20,000 rows it will take some time to compute the formulas (my summary array is approx 80 x 30 cells)
I think I'll leave my computer running over the weekend & hope that by Monday morning all the figures are there!
Still, its a darn sight quicker than me calculating it manually!

If the data in Data is sorted say on the first column, we can speed up the calculations.
 
Upvote 0
I can sort it by the first column, then the second. Does this make it quicker automatically or will I need to change the code?
 
Upvote 0
barkley said:
I can sort it by the first column, then the second. Does this make it quicker automatically or will I need to change the code?

The exhibit below shows how the array-formulas can be restricted to apply to relevant subranges, enabled by the sorted data...
aaCondUniqueCount barkley.xls
ABCDEFG
1
23192225
3ABBABN
4BEQUIPName500
5BEQUIPNumber600
6BLDMNTName200
7BLDMNTNumber200
8BLDREPName400
9BLDREPNumber300
10CASHName000
11CASHNumber000
12
Summary


First define BigStr...

Activate Insert|Name|Define.
Enter BigStr as name in the Names in Workbook box.
Enter the following in the Refers to box:

9.99999999999999E+307

Click OK.

Formulas:

C2, which is copied across to E2..

=MATCH(C3,Data!$A:$A,0)

Row 2 must all names in alphabetical order.

The last cell in row 2 (in the above exhibit, it's F2) must house:

=MATCH(BigStr,Data!A:A)

Array-formulas:

C4, which is copied across:

=SUM(IF(FREQUENCY(IF((OFFSET(Data!$A$1,C$2-1,0,D$2-C$2,1)=C$3)*(OFFSET(Data!$B$1,C$2-1,0,D$2-C$2,1)=$A4),MATCH(OFFSET(Data!$C$1,C$2-1,0,D$2-C$2,1),OFFSET(Data!$C$1,C$2-1,0,D$2-C$2,1),0),""),IF((OFFSET(Data!$A$1,C$2-1,0,D$2-C$2,1)=C$3)*(OFFSET(Data!$B$1,C$2-1,0,D$2-C$2,1)=$A4),MATCH(OFFSET(Data!$C$1,C$2-1,0,D$2-C$2,1),OFFSET(Data!$C$1,C$2-1,0,D$2-C$2,1),0),""))>0,1))

D4, which is copied across:

=SUM(IF(FREQUENCY(IF((OFFSET(Data!$A$1,C$2-1,0,D$2-C$2,1)=C$3)*(OFFSET(Data!$B$1,C$2-1,0,D$2-C$2,1)=$A4),OFFSET(Data!$D$1,C$2-1,0,D$2-C$2,1)),IF((OFFSET(Data!$A$1,C$2-1,0,D$2-C$2,1)=C$3)*(OFFSET(Data!$B$1,C$2-1,0,D$2-C$2,1)=$A4),OFFSET(Data!$D$1,C$2-1,0,D$2-C$2,1)))>0,1))

Select C4:D5 and copy down.
 
Upvote 0
Thank you Aladin for all your help.
I will give this a go on Monday morning and let you know how I get on.
Regards,
Darren
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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