Another Countif Query

Fazila

Board Regular
Joined
Nov 19, 2014
Messages
163
Hello

I have a table similar to the one below:

English TeacherEnglish Teacher TargetEnglish Teacher AssessmentMaths TeacherMaths Teacher TargetMaths Teacher AssessmentScience TeacherScience Teacher TargetScience Teacher Assessment
abb-eddiss+
bdbfsd+jmm-
csb+gms-kbb
dmd-hbs+ldb+

<tbody>
</tbody>

I need to count the number of bs, ds, s' and ms in all the columns headed with ...Teacher Assessment.

The formula I have tried to use so far is =SUM(COUNTIF(INDEX(RawData,0,MATCH("*teacher assessment*",RawDataHeadings,0)),{"b-";"s1";"s2";"s3";"b-1";"b-2";"b-3"})) (the bit in bold highlights the many variations I need to count but only for this column).

For the other columns it will be simply B, B+, D- etch.

The result it is returning is 2 - the result should be well over 200.

Any ideas as to where I am going wrong?

Thanks
 
Sorry people I really have tried to work this out but I'm really struggling:

Aladin and Steve's formulas worked great to count the overall number but now I need to count the number of cells containing teacher assessment and B and where column G contains M (this will change to take other factors into account).

So what I need is
NORB-,S1,S2,S3,B-1,B-2,B-3BB+D-DD+S-SS+
OverallAll Pupils296Count the number of the above values occur in columns with heading Teacher Assessment
GenderMale185Count the number of the above values occur in columns with heading Teacher Assessment and column G equals "M"
Female111Count the number of the above values occur in columns with heading Teacher Assessment and column G equals "F"

<tbody>
</tbody>

any thoughts?
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I'm guessing a bit at how your sheet is organized. I'm basing it on your original post. But you said that the gender is in column G, which was already used, so I put it in L. These formulas should work, but you'll have to adjust the ranges.

These formulas are just tweaking Steve's latest version. The D9 formula is just Steve's formula, but I changed it so that it reads the desired values from the header row, so you don't need to change every formula. Put the formula in D9 and drag right. It will handle letters or numbers.

The D10 formula is the same with the gender condition included. It reads the desired gender from column B, so you won't need to include that in the formula. Other conditions can be added in a similar way.

ABCDEFGHIJKLMN
1English TeacherEnglish Teacher TargetEnglish Teacher AssessmentMaths TeacherMaths Teacher TargetMaths Teacher AssessmentScience TeacherScience Teacher TargetScience Teacher AssessmentGender
2abb-eddiss+m
3bdbfsd+jmm-m
4csb+gms-kb1f
5dmd-hbs+ldb+f
6
7
8SummaryNORB-,S1,S2,S3,B-1,B-2,B-3BB+D-DD+S-SS+1d,d+,s+
9All Pupils11211110214
10m11001100103
11f00210010111

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

Array Formulas
CellFormula
D9{=SUM(IF(ISNUMBER(SEARCH("Teacher Assessment",$A$1:$I$1)),IF(ISNUMBER(SEARCH(","&$A$2:$I$5&",",","&D$8&",")),1)))}
D10{=SUM(IF(ISNUMBER(SEARCH("Teacher Assessment",$A$1:$I$1)),IF(ISNUMBER(SEARCH(","&$A$2:$I$5&",",","&D$8&",")),1)*($L$2:$L$5=$B10)))}

<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>
 
Upvote 0
Thanks for posting this Eric its not quite working yet but I've compromised and grouped all my Teacher Assessment columns together and used a sumproduct formula. If you have a minute could you break the formula down for me so I can see if where I am going wrong.

Thanks

Fazila
 
Upvote 0
Hmm, the theory behind it isn't that hard, but the details are a bear! It's very easy to get rows/columns mixed up in a formula like this. Also, understanding how Excel multiplies 2 arrays together can be a little headache-inducing. But I'll give it a shot.

=SUM(IF(ISNUMBER(SEARCH("Teacher Assessment",$A$1:$I$1)),IF(ISNUMBER(SEARCH(","&$A$2:$I$5&",",","&D$8&",")),1)*($L$2:$L$5=$B10)))

The section in red creates an internal array containing all of the values from A2:I5 surrounded by commas:

ABCDEFGHI
14,a,,b,,b-,,e,,d,,d,,i,,s,,s+,
15,b,,d,,b,,f,,s,,d+,,j,,m,,m-,
16,c,,s,,b+,,g,,m,,s-,,k,,b,,1,
17,d,,m,,d-,,h,,b,,s+,,l,,d,,b+,

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



Internally, the array is represented by {}, with a comma indicating next item, and a semicolon indicating next row, but this is easier to visualize.

=SUM(IF(ISNUMBER(SEARCH("Teacher Assessment",$A$1:$I$1)),IF(ISNUMBER(SEARCH(","&$A$2:$I$5&",",","&D$8&",")),1)*($L$2:$L$5=$B10)))

The part in red now puts commas around the header, so it looks like: ",B-,S1,S2,S3,B-1,B-2,B-3,". Since this is an array formula, now it checks to see if each value is in the header. We had to put commas around the values to make sure we don't get unintentional matches. A SEARCH will return either the offset into the string, or an error. So if it's a number (ISNUMBER), we know that we have a match, and we put a 1 in that location in the array, otherwise it defaults to FALSE:

ABCDEFGHI
14FALSEFALSE1FALSEFALSEFALSEFALSEFALSEFALSE
15FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE
16FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE
17FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE

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


This table now represents all the cells in A2:I5 that match one of the codes in the header.

=SUM(IF(ISNUMBER(SEARCH("Teacher Assessment",$A$1:$I$1)),IF(ISNUMBER(SEARCH(","&$A$2:$I$5&",",","&D$8&",")),1)*($L$2:$L$5=$B10)))

This part checks for the gender. It creates a vertical array of TRUE/FALSE, based on whether L2:L5 equals the gender code in B10.

M
2TRUE
3TRUE
4FALSE
5FALSE

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




=SUM(IF(ISNUMBER(SEARCH("Teacher Assessment",$A$1:$I$1)),IF(ISNUMBER(SEARCH(","&$A$2:$I$5&",",","&D$8&",")),1)*($L$2:$L$5=$B10)))

Now we multiply the 2 arrays together. In this type of array multiplication, all the values in the top row of the first array are multiplied by the top value of the second array. All the values in the second row of the first array are multiplied by the second row of the second array, and so on. Also, in this kind of multiplication TRUE=1 and FALSE=0. Excel will coerce all the Boolean values to 0/1 values:

ABCDEFGHI
14001000000
15000000000
16000000000
17000000000

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



This now represents all the cells that match the header, AND that match the gender flag.

=SUM(IF(ISNUMBER(SEARCH("Teacher Assessment",$A$1:$I$1)),IF(ISNUMBER(SEARCH(","&$A$2:$I$5&",",","&D$8&",")),1)*($L$2:$L$5=$B10)))

This part now looks at the column headings. If "Teacher Assessment" is in the heading, it takes the matching column from our array. If it isn't, it puts FALSE in all the rows of that column. If you put all the assessment columns together, you won't need this, just pick the right range.

Then finally, the SUM will add up all the cells in the array. At this point they will all be 1 or FALSE, and FALSE counts as 0.


So that's it. Pretty technical, and easy to miss a comma somewhere, even if you grasp the logic behind it. Hope this helps!
 
Upvote 0
That makes sense Eric and thank you for helping me - will be looking at the document again so thought it best to start getting my head around the whole process :)
 
Upvote 0
Another countif query

I am trying use a countifs formula with index match but keep getting #VALUE . The formula I am using is

=countifs(index(rawdata,0,match(a2,rawdataheadings,0)),"<>"&"",KS2A,">=4")/n2

In essence, if the column matching a2 has any data then to count where entries in column KS2A has a value of 4 or above.

If I change to countif the formula works but the countifs won't. Any thoughts?

Thanks
 
Upvote 0

Forum statistics

Threads
1,216,385
Messages
6,130,314
Members
449,572
Latest member
mayankshekhar

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