Jon Fuller
Jon Fuller

Reputation: 305

CountIf statement excel

I want to be able to check if data in one cell in column a = x and then if so count the data in adjacent cell in column b.

To explain in more detail, I am creating a statistics chart where commissioners need to be able to be able to compare data for region 1 to region 2 and region 3.

So column A will contain region keys such as 1, 1, 1, 2, 3, 3 then in column B will be ages. So if column A contains a 1 collect data in cell adjacent to the cell it is counting.

I hope this makes sense.

So I want the formula to only count the cells that adjacent cells contain district 1 for example

table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
<table style="width:100%">
  <tr>
    <td>A</td>
    <td>B</td>		
    
  </tr>
  
 <tr>
    <td>District 1</td>
    <td>12</td>		
    
  </tr>
 <tr>
    <td>District 2</td>
    <td>12</td>		
    
  </tr>
 <tr>
    <td>District 1</td>
    <td>12</td>		
    
  </tr>

 <tr>
    <td>District 2</td>
    <td>12</td>		
    
  </tr>
</table>

Upvotes: 2

Views: 170

Answers (1)

ydaetskcoR
ydaetskcoR

Reputation: 56997

You just need to use COUNTIFS() to add extra criteria to when to count something.

Using the following data:

Region  Age
2       12
2       16
2       41
1       62
3       26
3       50
2       12
1       65
3       64

Where Region = B1 we can use =COUNTIFS(A2:A10,2,B2:B10,12) to count the instances where Region = 2 and where Age = 12. This returns 2.

Obviously we can expand this out to all manner of criteria or keep adding extra criteria. Having data that looks like:

Region  Age Ethnicity
2       12  Black
2       16  Caucasian
2       41  Asian
1       62  Black
3       26  Caucasian
3       50  Asian
2       12  Caucasian
1       65  Caucasian
3       64  Asian

We can now count Asian people equal to or over the age of 50 in region 3 with =COUNTIFS(A2:A10,3,B2:B10,">=50",C2:C10,"Asian")

And if you want to bucket people using upper and lower bounds it's simply a case of creating the bound in separate ranges and criteria pairs. For instance to find all people in region 2 aged between 10 and 20 (not inclusive on the upper bound) we would use =COUNTIFS(A2:A10,2,B2:B10,">=10",B2:B10,"<20")

Upvotes: 1

Related Questions