Cumulative unique count - Excel 2010

excell_hell

New Member
Joined
Feb 10, 2014
Messages
4
Having difficulty solving this one:

I have a large spreadsheet, but am mostly interested in 2 columns of data (both text fields). A simplified example below:
TeacherStudent ID
Sally1234K
John5678K
Sally1234K
Peter1234K
Peter5678K
Sally8765K
John1234K
John8765K
John5678K

<tbody>
</tbody>

I initially just needed to count unique students per teacher. This was fine, eg. Sally - 2, John - 3, Peter - 2.

What I need now is a cumulative unique count, based on an order I define. So if I chose the order Peter, Sally then John, the unique counts would be as follows:
Peter: 2
Sally: 1
John: 0
= 3, as there is 3 unique combinations in total.

I need to be able to change the order of teacher to test some theories, so it needs to be based on cell references. Also there is approx 100 "teachers" and 10,000 "students". I have the data in one worksheet, and am doing the counting/ordering on another worksheet.

Help!? It's probably straight forward, but I am quite new to formulas used for unique counts and I can't work it out.

I need it via formula not through a pivot table.

Any ideas? If you need more info let me know.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

Forgive me if I'm missing the obvious, but I cannot work out how you arrive at your desired results of 2, 1 and 0 based on your chosen order: could you offer a brief explanation?

Regards
 
Upvote 0
Sorry, I probably should have spelled it out better. Basically they are unique student ID counts, BUT, if the student ID has already been counted in another teacher, don't count it again. There is only 3 unique Student IDs, so no matter what order I count the teachers in, the total should always be 3.

So in my example order (Peter > Sally > John):
Peter gets 2 (1234K, 5678K)
Sally only gets 1 for 8765K (as 1234K has already been counted in Peter)
John gets none because all student IDs have already been counted in Peter & Sally.

Does this make sense?
 
Upvote 0
Ok, then assuming that your original data table is in the range A1:B10 (with headers in row 1), and that you put Peter, Sally and John in D2:D4, enter this array formula** in E2:

=SUM(IF(FREQUENCY(IF($A$2:$A$10=D2,MATCH($B$2:$B$10,$B$2:$B$10,0)),ROW($B$2:$B$10)-MIN(ROW($B$2:$B$10))+1),1))


Then, in E3:

=SUM(IF(FREQUENCY(IF($A$2:$A$10=D3,IF(ISNA(MATCH($B$2:$B$10,IF(ISNUMBER(MATCH($A$2:$A$10,D$2:D2,0)),$B$2:$B$10),0)),MATCH($B$2:$B$10,$B$2:$B$10,0))),ROW($B$2:$B$10)-MIN(ROW($B$2:$B$10))+1),1))


Copy this latter to E4 (and obviously beyond if necessary).

Regards


**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
</SPAN></SPAN>
 
Upvote 0
Ok. Just noticed a space had somehow slipped into the second formula when I posted. Should be of course:

=SUM(IF(FREQUENCY(IF($A$2:$A$10=D3,IF(ISNA(MATCH($B$2:$B$10,IF(ISNUMBER(MATCH($A$2:$A$10,D$2:D2,0)),$B$2:$B$10),0)),MATCH($B$2:$B$10,$B$2:$B$10,0))),ROW($B$2:$B$10)-MIN(ROW($B$2:$B$10))+1),1))

Regards
 
Upvote 0
Hmmm. The space persists, despite not showing in the formula when I go to edit it...
 
Upvote 0
Thanks XOR LX, it worked perfectly and you saved my butt! When I get a free moment I'm going to try to actually understand how it works ;)
 
Upvote 0
You're welcome! And come back in a few days if you still can't figure out how that formula works! :cool:
 
Upvote 0

Forum statistics

Threads
1,216,434
Messages
6,130,596
Members
449,584
Latest member
c_clark

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