EXCEL: multiple criteria, only one count per row

jakulski

New Member
Joined
Jan 17, 2017
Messages
15
Hello. Within an Excel workbook I have a worksheet that has 30 columns and more than 50,000 rows. Below, I’ve have copied 7 of the columns and 29 of the rows (not including the two column heading rows). Let’s call this worksheet 201617. On another worksheet (also below), which I will call Summary, I need to show the following:
  • for schools in a given region, the cumulative number of times that TB* (TB1, TB2, TB3, TB4, TB5) was used as an entry (regardless of how many times per incident);
of the 29 incidents listed, the total number of TB* entries was 36
  • for each school, the number of times TB* was used as an offense entry; and
Examples: Anywhere High = 11entries; Somewhere High = 5 entries
  • for each school, the number of incidents in which TB* was included as one or more of the offense entries.
Example: Anywhere High = 7 incidents in which TB* was used; Somewhere High = 4 incidents in which TB* was used

I need help on the second and third bullets above. I’ve tried coutnifs (definitely won’t work for the third bullet because it doesn’t work when wanting to count unduplicated info), sumifs, sumproduct, etc., but without luck. And though I’m pretty skilled with Excel, I’m still figuring out VBA, arrays, etc. Please help…and thank you in advance!

colA
colB
colC
colD
colE
colF
colG
School
ID
Name
PriOff
PriOff2
PriOff3
Reg
Anywhere Elem
1234569
Nakia
WP5
TB2
DR5
5
Anywhere Elem
1234576
Barry
TB1
BU1
TB5
5
Anywhere Elem
1234585
Sharon
TB1
TB5

5
Anywhere High
1234573
Alexei
DC6
TB2
TB4
5
Anywhere High
1234581
Gregory
TB2
DC2

5
Anywhere High
1234567
Asia
TB5
DR5
AT5
5
Anywhere High
1234594
Robert
AL1
AL2
AL4
5
Anywhere High
1234582
Leah
TB1
TB2

5
Anywhere High
1234588
Luciano
TB4
BA1

5
Anywhere High
1234574
Alexei
DR8
DC9
TB4
5
Anywhere High
1234589
Mahemuti
DC4
BA2
RT1
5
Anywhere High
1234580
Efrain
TB1
TB5
TB2
5
Anywhere Middle
1234584
Keisha
TB1
TB5

5
Anywhere Middle
1234575
Bo Sun
TB1
TB2
TB4
5
Anywhere Middle
1234568
Lawrence
TB2
TB5
TB4
5
Anywhere Middle
1234591
Mohammad
DC4
BU2

5
Somewhere Elem
1234595
Tayelor
HO1
AL2
AL4
5
Somewhere Elem
1234593
Barbara
AL1
AT1
AL4
5
Somewhere Elem
1234579
Douglas
TB1
TB2

5
Somewhere Elem
1234587
Leenah
RO1


5
Somewhere Elem
1234583
Kyle
TB1
TB2

5
Somewhere Elem
1234572
Alexys
WX5
DR8
TB2
5
Somewhere High
1234577
Brandon
TB2
AT5

5
Somewhere High
1234570
Armani
DP1
AL2
TB2
5
Somewhere High
1234590
Mia
TB5


5
Somewhere High
1234586
Holly
TB1
TB5

5
Somewhere Middle
1234592
Rella
AL1
AL2
AL4
5
Somewhere Middle
1234571
Ann
DR8
DP1
TB2
5
Somewhere Middle
1234578
Diego
TB2
AT5

5

<tbody>
</tbody>
<strike>
</strike>

Summary

# of
Inc
TB1
TB2
TB3
TB4
TB5

PriOff
PriOff2
PriOff3
PriOff
PriOff2
PriOff3
PriOff
PriOff2
PriOff3
PriOff
PriOff2
PriOff3
PriOff
PriOff2
PriOff3
Anywhere Elem
3
2
0
0
0
1
0
0
0
0
0
0
0
0
1
1
Anywhere Middle
4
2
0
0
1
1
0
0
0
0
0
0
2
0
2
0
Anywhere High
9
2
0
0
1
2
1
0
0
0
1
0
2
1
1
0
Somewhere Elem
6
2
0
0
0
2
1
0
0
0
0
0
0
0
0
0
Somewhere Middle
3
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
Somewhere High
4
1
0
0
1
0
1
0
0
0
0
0
0
1
1
0






<tbody>
</tbody>

<tbody>
</tbody>
 

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.
NOTE: THIS IS A CORRECTED POST -THE FORMATTING WAS OFF ON THE SECOND CHART (NOT THAT IT'S SO HOT NOW, BUT IT'S THE BEST I COULD DO WITH THE FORMATTING OPTIONS AVAILABLE)

Hello. Within an Excel workbook I have a worksheet that has 30 columns and more than 50,000 rows. Below, I’ve have copied 7 of the columns and 29 of the rows (not including the two column heading rows). Let’s call this worksheet 201617. On another worksheet (also below), which I will call Summary, I need to show the following:


  • for schools in a given region, the cumulative number of times that TB* (TB1, TB2, TB3, TB4, TB5) was used as an entry (regardless of how many times per incident);
of the 29 incidents listed, the total number of TB* entries was 36

  • for each school, the number of times TB* was used as an offense entry; and
Examples: Anywhere High = 11entries; Somewhere High = 5 entries

  • for each school, the number of incidents in which TB* was included as one or more of the offense entries.
Example: Anywhere High = 7 incidents in which TB* was used; Somewhere High = 4 incidents in which TB* was used

I need help on the second and third bullets above. I’ve tried coutnifs (definitely won’t work for the third bullet because it doesn’t work when wanting to count unduplicated info), sumifs, sumproduct, etc., but without luck. And though I’m pretty skilled with Excel, I’m still figuring out VBA, arrays, etc. Please help…and thank you in advance!

colA
colB
colC
colD
colE
colF
colG
School
ID
Name
PriOff
PriOff2
PriOff3
Reg
Anywhere Elem
1234569
Nakia
WP5
TB2
DR5
5
Anywhere Elem
1234576
Barry
TB1
BU1
TB5
5
Anywhere Elem
1234585
Sharon
TB1
TB5

5
Anywhere High
1234573
Alexei
DC6
TB2
TB4
5
Anywhere High
1234581
Gregory
TB2
DC2

5
Anywhere High
1234567
Asia
TB5
DR5
AT5
5
Anywhere High
1234594
Robert
AL1
AL2
AL4
5
Anywhere High
1234582
Leah
TB1
TB2

5
Anywhere High
1234588
Luciano
TB4
BA1

5
Anywhere High
1234574
Alexei
DR8
DC9
TB4
5
Anywhere High
1234589
Mahemuti
DC4
BA2
RT1
5
Anywhere High
1234580
Efrain
TB1
TB5
TB2
5
Anywhere Middle
1234584
Keisha
TB1
TB5

5
Anywhere Middle
1234575
Bo Sun
TB1
TB2
TB4
5
Anywhere Middle
1234568
Lawrence
TB2
TB5
TB4
5
Anywhere Middle
1234591
Mohammad
DC4
BU2

5
Somewhere Elem
1234595
Tayelor
HO1
AL2
AL4
5
Somewhere Elem
1234593
Barbara
AL1
AT1
AL4
5
Somewhere Elem
1234579
Douglas
TB1
TB2

5
Somewhere Elem
1234587
Leenah
RO1


5
Somewhere Elem
1234583
Kyle
TB1
TB2

5
Somewhere Elem
1234572
Alexys
WX5
DR8
TB2
5
Somewhere High
1234577
Brandon
TB2
AT5

5
Somewhere High
1234570
Armani
DP1
AL2
TB2
5
Somewhere High
1234590
Mia
TB5


5
Somewhere High
1234586
Holly
TB1
TB5

5
Somewhere Middle
1234592
Rella
AL1
AL2
AL4
5
Somewhere Middle
1234571
Ann
DR8
DP1
TB2
5
Somewhere Middle
1234578
Diego
TB2
AT5

5

<tbody>
</tbody>


Summary


TB1 TB1 TB1
TB2 TB2 TB2
TB3 TB3 TB3
TB4 TB4 TB4
TB5 TB5 TB5

# of
Inc
PriOff
PriOff2
PriOff3PriOff
PriOff2
PriOff3
PriOff
PriOff2
PriOff3
PriOff
PriOff2
PriOff3
PriOff
PriOff2
PriOff3
Anywhere Elem
3
2
0
0
0
1
0
0
0
0
0
0
0
0
1
1
Anywhere Middle
4
2
0
0
1
1
0
0
0
0
0
0
2
0
2
0
Anywhere High
9
2
0
0
1
2
1
0
0
0
1
0
2
1
1
0
Somewhere Elem
6
2
0
0
0
2
1
0
0
0
0
0
0
0
0
0
Somewhere Middle
3
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
Somewhere High
4
1
0
0
1
0
1
0
0
0
0
0
0
1
1
0

<tbody>
</tbody>
 
Last edited:
Upvote 0
You didn't say how you generated your Summary table results so far. I created a formula (C4) that creates those totals. Drag the formula down and to the right as needed. The tricky part is determining the TB1, TB2, etc. that is needed. I came up with a tricky OFFSET function to do it, but it really would be easier to just put "TB1" in C1:E1, and format C1 and E1 so that it is hidden.

ABCDEFGHIJKLMNOPQRS
1TB1TB2TB3TB4TB5
2
3# of incPriOffPriOff2PriOff3PriOffPriOff2PriOff3PriOffPriOff2PriOff3PriOffPriOff2PriOff3PriOffPriOff2PriOff3Total TB* offenses
4Anywhere Elem32000100000000115
5Anywhere Middle32001100000020208
6Anywhere High720012100010211011
7Somewhere Elem32000210000000005
8Somewhere Middle20001010000000002
9Somewhere High41001010000001105
10
11
12Total for region36

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet4

Worksheet Formulas
CellFormula
C4=COUNTIFS('201617'!$A:$A,$A4,INDEX('201617'!$D:$F,0,MATCH(C$3,'201617'!$D$1:$F$1,0)),OFFSET($C$1,,INT((COLUMNS($C4:C4)-1)/3)*3))
S4=SUM(C4:Q4)
B12=SUM(C4:Q9)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
B4{=SUM(('201617'!$A$2:$A$30=A4)*(MMULT((LEFT('201617'!$D$2:$F$30,2)="TB")+0,{1;1;1})>0))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



Given that table, your bullet points 1 and 2 are easy. Total for the region in in B12, and the total by school is in S4 and down.

Bullet point 3 is trickier. I used a MMULT function to act as an OR. It works well, but it may bog your sheet down a lot if you have 30,000 rows. Hope this helps, let us know.
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

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