← Working with data

Count and decide

IF lets a cell decide: =IF(test, answer if true, answer if not). A test compares cells with signs such as >=, and words in an answer go inside quote marks. COUNTIF counts how many cells in a range match a rule, such as >=10 or "Tall". Together they turn a column of numbers into sorted-out groups and counts that follow when the numbers change.

A scientist wants to know how many beans are 'tall'. She could look down the column and count. What if the sheet could decide for each plant, and count for her?

Eight beans were measured on day 10 (in cm). This scientist calls a bean Tall if it is 10 cm or more, and Short if not. Column C decides with IF, and B11 counts the Tall ones with COUNTIF.

A B C
1 Plant Height (cm) Size
2 Bean A 8.5 Short
3 Bean B 10 Tall
… … … …
11 Tall plants 4

C2 holds this formula, and each cell below has the same kind. B11 holds the COUNTIF:

C2:   =IF(B2>=10,"Tall","Short")
B11:  =COUNTIF(C2:C9,"Tall")
How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
Extra examplesYour teacher may tell you which.
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

What happens to the count?

4 beans are Tall, so B11 shows 4. Bean A in B2 is 8.5, so C2 shows Short. B2 is changed to 10.5. What does B11 show?

TryTry it on the board and compare the result with your prediction.

Try: change a height

Was your guess right? Bean B is exactly 10 cm and is already Tall, because the test is >=, which means 'greater than or equal to'.

Try it yourselfYour edits are saved in this browser.
Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

Click B2, type 10.5 and press Enter.

Another hint

Watch C2 change, then B11.

Change Bean A's height in B2 to 10.5. What does the count of Tall plants in B11 show?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: decide, then count

Worked exampleBefore each step, say what you think comes next.
  1. =IF(test,if true,if not)\texttt{=IF(} \text{test} \texttt{,} \text{if true} \texttt{,} \text{if not} \texttt{)}IF has three parts, separated by commas.

Now: what does IF show?

What does =IF(B2>=10,"Tall","Short") show when B2 holds 12?

Sam's C2 shows #NAME? instead of Tall or Short. Click the line where Sam first goes wrong.

What does =COUNTIF(B2:B9,">=10") count?

ModifyChange the problem on purpose and see what happens.

Vary: change the test

The heights are 8.5, 10, 9.5, 12, 11, 9, 13.5 and 7. What does =COUNTIF(B2:B9,">=10") show?

B2 holds exactly 10. What does =IF(B2>10,"Tall","Short") show?

You want C2 to say Healthy if the height in B2 is more than 8, and Check if not. Which formula do you write?

PractiseA few on your own, to check you have it.

Decide and count

Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

In C2 type =IF(B2>=10,"Tall","Short") and fill it down to C9.

Another hint

B11 already counts the Tall plants, so it shows 4 when your IF column is right.

Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

Click B12 and type a COUNTIF on the heights in B2:B9. The rule goes in quotes, such as "<9".

Try it yourselfYour edits are saved in this browser.
Every bean has a Tall or Short answer in column C, and B11 counts the Tall ones. Bean F in B7 grows from 9 to 10.5. What happens to the count in B11?

Write an IF formula in C2 that says Tall for 10 or more and Short if not. Fill it down to C9.

Use the board. This ticks when you get there.

The sizes are filled in. In B12, count how many plants are shorter than 9 cm.

Use the board. This ticks when you get there.

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

A quiz result

Change one score from under 5 to over 5. Which two cells move?

Try it yourselfYour edits are saved in this browser.
Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

Type eight quiz scores out of 10 in B2 to B9, some under 5 and some 5 or more.

Another hint

In C2 write =IF(B2>=5,"Pass","Retry") and fill down. Then COUNTIF in B11 for Pass and B12 for Retry.

Type eight quiz scores, some under 5 and some 5 or more. Write an IF in C2 (5 or more is Pass, otherwise Retry) and fill it down. Count the Pass cells in B11 and the Retry cells in B12.

Use the board. This ticks when you get there.

Make Extra · typicalMake your own problem using what you have learned. Expect a few tries; that is normal.

In your own spreadsheet app

Excel, Google Sheets and Numbers all have IF and COUNTIF with the same parts. Words go in quote marks and so does a rule such as ">=10". Capital letters in the words do not matter to COUNTIF. If a cell shows #NAME?, check the quote marks first.

Now you can
Next lesson7. Put the rows in orderSorting puts the rows of a table in order by one column, and moves whole rows so every row keeps its own numbers. Filtering hides the rows that do not match a rule, without deleting them, so you can look at just the ones you want. Both work on the whole table, headings included, and neither changes the data itself.
For teachers

Students use IF to make a cell decide between two answers and COUNTIF to count the cells that match a rule, both following when a number changes. They sort eight Year 7 bean heights into Tall and Short and count each group, then do the same for quiz scores, and repeat it in the spreadsheet app the school uses. About 45 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Do the Try board yourself: change B2 and watch C2, then B11.

The one idea: IF lets a cell make a decision from other cells, and COUNTIF counts how many cells meet a rule. Both are formulas, so they work again when a number changes.

Comparison signs: = (equal), <> (not equal), > (more than), < (less than), >= (more than or equal), <= (less than or equal). A test using > leaves out the boundary value, which is a common slip: the boundary question in Vary is there for it.

Quote marks: words in a formula go in quotes. The sheet on the page shows #NAME? without them, as Excel and Sheets do. COUNTIF's rule is also in quotes (">=10", "Tall"), and does not mind capital letters.

Real tools: some offer smart quotes when pasted from a document, which breaks formulas. Type the quotes in the cell itself.

Running the lesson

  1. Predict: students who chose 4 think the count was fixed. Ask what C2 would show now and who changes it.
  2. Try: ask which cell changed first, C2 or B11, and why.
  3. Worked example: say the IF aloud as a sentence and ask what each comma separates.
  4. Practise: ask what the count would be if the rule were >10, and why Bean B changes sides.
  5. Own app: walk round. Common slips: missing quotes, a missing bracket, and > where >= was meant.

The hard part (on purpose)

Writing the three parts of IF in the right order, with words in quotes. Students who have never written a formula with commas find it fiddly: let them say it aloud first (if this, then that, otherwise this).

When students get stuck

Stretch and support

Stretch: Add a third group, Very tall, for 12 cm or more. Which function lets one IF choose between three answers? (Hint: put an IF inside an IF.)

Support: A card: =IF(test, answer if true, answer if not). Words go in "quotes". >= means 10 or more; > means more than 10.

Where it leads

Next in Working with data: Put the rows in order (sort and filter).

Science: sorting measurements into groups (tall and short, healthy and not) is the first step to comparing them. A cut-off such as 10 cm is a choice: ask students why that one.

What each step is for