Counting Across Tables

leefletcher

New Member
Joined
Mar 22, 2018
Messages
29
Office Version
  1. 2019
Platform
  1. Windows
Hello!

I am trying to count items but they are linked across tables.

Sheet 1 - Has the schools listed by city
CitiesSchools
BostonMaple Elementary
BostonElm Middle School
BostonCedar Elementary
Los AngelesBamboo Elementary
New YorkPine High School
New YorkFicus High School

Sheet 2 - Shows which grade levels are in the school
SchoolsGrades
Woodruff Elementary1st-5th
Cedar Elementary5th-6th
Elm Middle School6th-8th
Ficus High School9th-10th
Landrum High School9th-12th
Northwest Elementaryk-5th

Sheet 3 - Tells me the grade level types that each grade level is assigned
GradesTypes
1st-5the
5th-6thm
6th-8thm
9th-10thh
9th-12thh
k-5the

How do I count the number of "types" in each town? Like this:
emh
Boston
1​
2​
0​
New York
0​
0​
2​
Los Angeles
1​
0​
0​
 
Since the schools have districts, I added a 3rd column and put the districts in there and tried to use this:
=SUM(IF($A$3:$A$8=$A30,IF(ISNUMBER(MATCH(($B$3:$B$8*C3:C8),IF(ISNUMBER(MATCH($B$12:$B$17,IF($B$21:$B$26=B$29,$A$21:$A$26),0)),($A$12:$A$17*C12:C17)),0)),1)))
Sadly, it didn't work.

Any thoughts on how to Match including the district since I have 2 schools in the state with the same name but are in different districts?
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Can you post your revised tables, along with the expected results?
 
Upvote 0
Domenic-

I got it to work with &, but here's what they look like:

Sheet 1 - Has the schools listed by city
CitiesSchoolsDistrict
BostonMaple ElementaryPear District 01
BostonElm Middle SchoolPear District 01
BostonCedar ElementaryPear District 01
Los AngelesBamboo ElementaryApple District 01
New YorkPine High SchoolOrange District 01
New YorkFicus High SchoolLime District 01
Sheet 2 - Shows which grade levels are in the school
SchoolsGradesDistrict
Maple Elementary1st-5thPear District 01
Cedar Elementary5th-6thPear District 01
Elm Middle School6th-8thPear District 01
Ficus High School9th-10thLime District 01
Pine High School9th-12thOrange District 01
Bamboo Elementaryk-5thApple District 01
Sheet 3 - Tells me the grade level types that each grade level is assigned
GradesType
1st-5the
5th-6the
6th-8thm
9th-10thh
9th-12thh
k-5the
How do I count the number of "types" in each town? Like this:
emh
Boston
2​
1​
0​
New York
0​
0​
2​
Los Angeles
1​
0​
0​

=SUM(IF($A$3:$A$8=$A30,IF(ISNUMBER(MATCH(($B$3:$B$8&$C$3:$C$8),IF(ISNUMBER(MATCH($B$12:$B$17,IF($B$21:$B$26=B$29,$A$21:$A$26),0)),($A$12:$A$17&$C$12:$C$17)),0)),1)))

I do have a follow-up question: Some schools won't have grades but they will have an "Other" tag (e.g., charter, alternative, technical). How do I first check to see if there is a "grade" and then use the "other" to apply the Type?



Sheet 1 - Has the schools listed by city
CitiesSchoolsDistrict
BostonMaple ElementaryPear District 01
BostonElm Middle SchoolPear District 01
BostonCedar ElementaryPear District 01
Los AngelesBamboo ElementaryApple District 01
New YorkPine High SchoolOrange District 01
New YorkFicus High SchoolLime District 01
Sheet 2 - Shows which grade levels are in the school
SchoolsGradesDistrictOther
Maple Elementary1st-5thPear District 01
Cedar Elementary5th-6thPear District 01
Elm Middle School6th-8thPear District 01
Ficus High School9th-10thLime District 01
Pine High SchoolOrange District 01Charter
Bamboo Elementaryk-5thApple District 01
Sheet 3 - Tells me the grade level types that each grade level is assigned
GradesType1
1st-5the
5th-6the
6th-8thm
9th-10thh
9th-12thh
k-5the
CharterOther
How do I count the number of "types" in each town? Like this:
emhOther
Boston
2​
1​
0​
0​
New York
0​
0​
2​
0​
Los Angeles
0​
0​
0​
1​

When I've come across this in other formulas, I've added an If statement at the beginning to see if the "Grades" field is full. If it is, then I use the formula to return the data from the "Grades" column; if it isn't, then I use the formula to return the data from the "Other" column.
 
Upvote 0
Try...

VBA Code:
B31, confirmed with CONTROL+SHIFT+ENTER, copied across and down:

=SUM(IF($A$3:$A$8=$A31,IF(ISNUMBER(MATCH($B$3:$B$8&$C$3:$C$8,IF(ISNUMBER(MATCH($B$12:$B$17,IF($B$21:$B$27=B$30,$A$21:$A$27),0))+ISNUMBER(MATCH($D$12:$D$17,IF($B$21:$B$27=B$30,$A$21:$A$27),0)),$A$12:$A$17&$C$12:$C$17),0)),1)))

However, it probably would be a bit more efficient to split the solution into two formulas. The first one as per your amended formula...

VBA Code:
B31, confirmed with CONTROL+SHIFT+ENTER, copied across to D31, and down:

=SUM(IF($A$3:$A$8=$A31,IF(ISNUMBER(MATCH($B$3:$B$8&$C$3:$C$8,IF(ISNUMBER(MATCH($B$12:$B$17,IF($B$21:$B$27=B$30,$A$21:$A$27),0)),$A$12:$A$17&$C$12:$C$17),0)),1)))

And then a second one for your Other column...

VBA Code:
E31, confirmed with CONTROL+SHIFT+ENTER, and copied down:

=SUM(IF($A$3:$A$8=$A31,IF(ISNUMBER(MATCH($B$3:$B$8&$C$3:$C$8,IF(ISNUMBER(MATCH($D$12:$D$17,IF($B$21:$B$27=E$30,$A$21:$A$27),0)),$A$12:$A$17&$C$12:$C$17),0)),1)))

Hope this helps!
 
Upvote 0
Solution
Thanks, again. I was able to construct the 2 column solution from above, however, I found 2 schools that have a Grade and a Type. I need to figure out which one we want to count it as and then figure out how to eliminate the double counting.
 
Upvote 0
One more twist: How do I add up the enrollment for each of the Levels?

Sheet 1 - Has the schools listed by city
CitiesSchoolsDistrict
BostonMaple ElementaryPear01
BostonElm Middle SchoolPear01
BostonCedar ElementaryPear01
Los AngelesBamboo ElementaryPear01
New YorkPine High SchoolPear01
New YorkFicus High SchoolPear01
Sheet 2 - Shows which grade levels are in the school
SchoolsGradesDistrictOtherEnrollment
Maple Elementary1st-5thPear01
400​
Cedar Elementary5th-6thPear01
500​
Elm Middle School6th-8thPear01
750​
Ficus High School9th-10thPear01
1000​
Pine High SchoolOrange District 01Charter
100​
Bamboo Elementaryk-5thPear01
250​
Sheet 3 - Tells me the grade level types that each grade level is assigned
GradesTypes
1st-5the
5th-6thm
6th-8thm
9th-10thh
9th-12thh
k-5the
How do I count the number of "types" in each town? Like this:
emhOther
Boston
400​
1250​
0​
0​
New York
0​
0​
1000​
100​
Los Angeles
250​
0​
0​
0​
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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