COUNTIFS formula that removes duplicate values in array

HeatherF

New Member
Joined
Mar 3, 2020
Messages
32
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a spreadsheet with unique student IDs in column A. Each ID may have multiple rows with different values in column D (student activities--maybe one row is Baseball and one is Glee Club). The formula below counts all the other rows that match that row's column D (activity) and column H (class year).

Column O =COUNTIFS($D$1:$D$68861,D2,$H$1:$H$68861,H2,$A$1:$A$68861,"<>"&A2)

I want the next column to total up all the people each ID matched with across multiple activities. I was doing this: =SUMIF($A$1:$A$68861,A2,$O$1:$O$68861) but then I realized if that individual was in baseball and glee club with the same classmate, that classmate is counted twice.

Is there a way to run the COUNTIFS formula above, then go through and remove duplicate values from column A?

Any ideas are very appreciated!

Thanks,

Heather
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
It's hard to throw together an example without seeing something for me, but maybe combining the Frequency formula?

 
Upvote 0
Thanks, I've pasted some of the table below. I was afraid it would be confusing. Basically O2 is counting all the people in Richard's class that also did Men's Swim and Dive. I want column P to count all the people from Richard's class that he did any activity with. But if I just SUM column O, it will count Martin as 3 people, because they did Men's Swim and Dive, Choir/Choral Club, and Delta Psi together.

Book2
ABCDEFGHIJKLMNO
1ID_NUMBERCATEGORYCODEACTIVITYSTOP_DTSTART_DTNAMECLASSGENDERRATINGMIN CONF CAPACITYLTGNETWORK MIN CONF CAPACITY - SINGLE ACTIVITYNETWORK LTG - SINGLE ACTIVITYACTIVITY NETWORK SIZE
26454254SPORTS87Men's Swim and DiveRICHARD1964MU0$375$50,000$49,9101
36454254STU_ACTS4Choir/Choral ClubRICHARD1964MU0$375$50,000$49,9101
46454254STU_ACTS125Civil Rights CommitteeRICHARD1964MU0$375$0$00
56454254STU_ACTS274Delta PsiRICHARD1964MU0$375$50,000$49,9101
66454254STU_ACTS7Gargoyle SocietyRICHARD1964MU0$375$0$00
76454254STU_ACTS102Glee ClubRICHARD1964MU0$375$0$00
86454254STU_ACTS9Junior AdvisorsRICHARD1964MU0$375$50,000$49,9101
96492235SPORTS87Men's Swim and DiveMARTIN1964M1050000$49,910$0$3751
106492235STU_ACTS1Band/SymphonyMARTIN1964M1050000$49,910$0$00
116492235STU_ACTS274Delta PsiMARTIN1964M1050000$49,910$0$3751
126492235STU_ACTS8Choir/Choral ClubMARTIN1964M1050000$49,910$0$3751
136492235STU_ACTS9Junior AdvisorsMARTIN1964M1050000$49,910$0$3751
146492235STU_ACTS59Marching BandMARTIN1964M1050000$49,910$0$00
156492235STU_ACTS56Theater Production ParticipantMARTIN1964M1050000$49,910$0$00
166374307SPORTS93Men's Ice HockeyTHOMAS1963MU0$3,140$0$00
176374307STU_ACTS134GurgleTHOMAS1963MU0$3,140$0$00
186374307STU_ACTS274Kappa AlphaTHOMAS1963MU0$3,140$0$00
196455382SPORTS99BaseballDAVID1964MN0$1,060$0$00
Sheet1
Cell Formulas
RangeFormula
M2:M19M2=SUMIFS($K$1:$K$68861,$D$1:$D$68861,D2,$H$1:$H$68861,H2,$A$1:$A$68861,"<>"&A2)
N2:N19N2=SUMIFS($L$1:$L$68861,$D$1:$D$68861,D2,$H$1:$H$68861,H2,$A$1:$A$68861,"<>"&A2)
O2:O19O2=COUNTIFS($D$1:$D$68861,D2,$H$1:$H$68861,H2,$A$1:$A$68861,"<>"&A2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
M1:M19,N1Other TypeColor scaleNO
 
Upvote 0
Tricky. Try:

Book1
ADGHOP
1IDActivityNameClassActivity Network SizeTotal Network Size
21Men's Swim and DiveRichard196415
31Choir/Choral ClubRichard19641 
41Civil Rights CommitteeRichard19642 
51Delta PsiRichard19642 
61Gargoyle SocietyRichard19641 
75Choir/Choral ClubMary196415
85Civil Rights CommitteeMary19642 
95Chess clubMary19644 
105GurgleMary19640 
113Chess clubEd196445
123Men's Swim and DiveEd19641 
133Junior AdvisorsEd19642 
143Men's Ice HockyEd19640 
159Glee clubSusan196414
169Chess clubSusan19644 
1722Civil Rights CommitteeBob196425
1822Chess clubBob19644 
1922Junior AdvisorsBob19642 
2010Chess clubMagnus196446
2110Delta PsiMagnus19642 
2210Glee clubMagnus19641 
2310Junior AdvisorsMagnus19642 
2499Gargoyle SocietyElayne196412
2599Delta PsiElayne19642 
26
Sheet11
Cell Formulas
RangeFormula
O2:O25O2=COUNTIFS($D$1:$D$68862,D2,$H$1:$H$68862,H2,$A$1:$A$68862,"<>"&A2)
P2:P25P2=IF(A2=A1,"",SUMPRODUCT(SIGN(FREQUENCY(IF(($H$2:$H$26=H2)*ISNUMBER(MATCH($D$2:$D$26,D2:INDEX(D:D,AGGREGATE(14,6,ROW(D2:D22)/(A2:A22=A2),1)),0)),$A$2:$A$26),$A$2:$A$26)))-1)


Adjust the ranges as needed. This will work for up to 20 activities per person. It would be easy to raise that number if necessary.
 
Upvote 0
Solution
Tricky. Try:

Book1
ADGHOP
1IDActivityNameClassActivity Network SizeTotal Network Size
21Men's Swim and DiveRichard196415
31Choir/Choral ClubRichard19641 
41Civil Rights CommitteeRichard19642 
51Delta PsiRichard19642 
61Gargoyle SocietyRichard19641 
75Choir/Choral ClubMary196415
85Civil Rights CommitteeMary19642 
95Chess clubMary19644 
105GurgleMary19640 
113Chess clubEd196445
123Men's Swim and DiveEd19641 
133Junior AdvisorsEd19642 
143Men's Ice HockyEd19640 
159Glee clubSusan196414
169Chess clubSusan19644 
1722Civil Rights CommitteeBob196425
1822Chess clubBob19644 
1922Junior AdvisorsBob19642 
2010Chess clubMagnus196446
2110Delta PsiMagnus19642 
2210Glee clubMagnus19641 
2310Junior AdvisorsMagnus19642 
2499Gargoyle SocietyElayne196412
2599Delta PsiElayne19642 
26
Sheet11
Cell Formulas
RangeFormula
O2:O25O2=COUNTIFS($D$1:$D$68862,D2,$H$1:$H$68862,H2,$A$1:$A$68862,"<>"&A2)
P2:P25P2=IF(A2=A1,"",SUMPRODUCT(SIGN(FREQUENCY(IF(($H$2:$H$26=H2)*ISNUMBER(MATCH($D$2:$D$26,D2:INDEX(D:D,AGGREGATE(14,6,ROW(D2:D22)/(A2:A22=A2),1)),0)),$A$2:$A$26),$A$2:$A$26)))-1)


Adjust the ranges as needed. This will work for up to 20 activities per person. It would be easy to raise that number if necessary.
Wow, thank you! That is elaborate but would probably work. I kept trying to think last night about how I might use hidden helper columns to compile network size totals then subtract dupes but I am at a loss. Thanks for your effort!
 
Upvote 0
Yes, it is elaborate, but I couldn't think of an easier way. I'll ponder a bit more. Newer versions of Excel have some new functions including FILTER and UNIQUE which would make this a snap.

Anyway, glad I could help, and thanks for the feedback! :)
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,857
Members
449,051
Latest member
excelquestion515

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