Excel Novice: Would like to define CountIFS Critera as a variable array.

Nementh

New Member
Joined
Jan 7, 2016
Messages
3
Hello all,

I've learned a lot over the years with excel, however I'm at a standstill on a particular problem. Long story short, I work for a school district, and need to provide total number of students each teacher has during any given day from our student information system.

The fastest way for me to export the data is to export all student schedules, and use countif to find how many a teacher appears in the raw data, the problem this year, is I've been asked to exclude students from some courses, and said courses may change per request of the report.

What I have so far is:

=SUM(COUNTIFS('HS Schedules'!O:O,I3,'HS Schedules'!N:N,INDIRECT(F1)))

'HS Schedules'!O:O = 6th hour teachers
I3 = teacher name.
'HS Schedules'!N:N = 6th hour classes
F1 = list of excluded courses I don't want to count.

F1 is built by a user placing a mark in a column, that then concatenates the value into a string. I concatenate the string result and format it as {"Footbal", "Golf"}

I can paste the value of F1 into

=SUM(COUNTIFS('HS Schedules'!O:O,I3,'HS Schedules'!N:N,{"Footbal", "Golf"}))

and it works, however I'm stuck at getting the formula to read the text value for the criteria

Open to thoughts or different suggestions.

Due to student data I cannot provide the worksheets, however; they are arranged as such:

HS Schedules

ABC...NO
Student #LastFirstPeriod1...Period 6 CoursePeriod 6 Teacher
123456lastfirst2D Art...FootballTeacher_1

<tbody>
</tbody>
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the MrExcel board!

F1 is built by a user placing a mark in a column, ..
1. What 'mark'?
2. What column?
3. What sheet?
4. What column are the courses in that the 'mark' is placed next to?
5. You say that F1 is a list of excluded courses, but =SUM(COUNTIFS('HS Schedules'!O:O,I3,'HS Schedules'!N:N,{"Footbal", "Golf"})) indicates that the list is being included. Can you clarify?
 
Last edited:
Upvote 0
Sorry Peter I didn't include that info. Here's what generates F1, and everything else on that sheet for reference.


ABCDEFGHIJK
1"=H3&H4&H5...&H421=CONCATENATE("{",LEFT(E1,LEN(E1)-1),"}")
2Teacher# of StudentsExcludeCourseStudentsTeacher# of StudentsExcluded
3Last_First=COUNTIF('HS Schedules'!A:O,A3)Art=COUNTIF('HS Schedules'!A:CA,E3)=IF(D3="","",CONCATENATE($C$1,E3,$C$1,";"))=A3=B3=SUM(COUNTIFS('HS Schedules'!O:O,I3,'HS Schedules'!N:N,INDIRECT(F1)))
4Last_First_1=COUNTIF('HS Schedules'!A:O,A4)XFootball=COUNTIF('HS Schedules'!A:CA,E4)=IF(D4="","",CONCATENATE($C$1,E4,$C$1,";"))=A4=B4=SUM(COUNTIFS('HS Schedules'!O:O,I4,'HS Schedules'!N:N,INDIRECT(F1)))

<tbody>
</tbody>



There's probably a better way to do D:H, but it was the fast way to do it. there are roughly 400 courses total, and 20-30 that are excluded, but for flexibility, I need to be able to include and exclude courses at various parts of the year.

If I paste F1's result {"Football","Lifetime Sports","Marching Band","Physical Fitness"} for example, in place of INDIRECT(F1) In K:K everything works as expected. I'd just prefer to make it work without having to paste, so I can send the workbook out to the people who analyze the data.

A:B will be moved to I:K later, they were my original #'s without excluded courses from last years data set.
 
Upvote 0
Here's one way to do it. Let me know if my sample sheets don't match yours.

The HS Schedules sheet:

Excel 2010
ABCDEFGHIJKLMNO
1Student #LastFirstPeriod1Period 6 CoursePeriod 6 Teacher
2123456lastfirst2D ArtFootballDoe_John
3111aaaFootballDoe_John
4222bbbGolfRoe_Mary
5333cccArtDoe_John
6444dddChemistryRoe_Mary
7555eeeGolfRoe_Mary
8666fffFootballDoe_John
9777gggFootballSmith_Ann
10888hhhGolfDoe_John
11999iiiChemistrySmith_Ann

<tbody>
</tbody>
HS Schedules



The teacher sheet:
Excel 2010
ABCDEFGHIJKLMNO
1Football2
2Teacher# of studentsExcludeCourseStudentsTeacher# of studentsExcludedGolf
3Roe_Mary3Art1Roe_Mary32
4Doe_John5XFootball4Doe_John54
5Smith_Ann2XGolf3Smith_Ann21
6Jones_Bob0Physics1Jones_Bob00

<tbody>
</tbody>
Teacher List

Worksheet Formulas
CellFormula
J3=B3
O1=COUNTIF(D1:D500,"X")

<tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
K3{=SUM(COUNTIFS('HS Schedules'!O:O,I3,'HS Schedules'!N:N,OFFSET('Teacher List'!$N$1,0,0,'Teacher List'!$O$1,1)))}
N1{=IFERROR(INDEX(E:E,SMALL(IF(D3:D500="X",ROW(D3:D500)),ROW())),"")}

<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>



I removed your E1, F1, and H formulas, and replaced them with a list in N. You can put this in H if you want, now that it's available. The N list contains the excluded courses. The O1 cell contains the number of excluded courses. Put the formula in N1, confirm it with Control-Shift-Enter. Then copy the cell and paste it down as far as necessary. Then put in the O1 formula. Then put in the K3 formula, confirm with Control-Shift-Enter, and paste it down the column.

Let me know if this works for you.

Edit: I have heard that the IFERROR function is fairly inefficient, and in a large spreadsheet might slow it down. The N1 formula can be replaced with:

=IF(ROW()<=$O$1,INDEX(E:E,SMALL(IF(D3:D500="X",ROW(D3:D500)),ROW())),"")

and confirm with Control-Shift-Enter. Then use it the same way.
 
Last edited:
Upvote 0
Glad to help! I'm constantly learning new things about Excel, that's one reason I like it!
 
Upvote 0

Forum statistics

Threads
1,215,159
Messages
6,123,348
Members
449,097
Latest member
thnirmitha

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