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:
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.
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.
I can use COUNTIF to count the cells that match a rule.
I can say when a quote mark is needed.
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
Predict: students who chose 4 think the count was fixed. Ask what C2 would show now and who changes it.
Try: ask which cell changed first, C2 or B11, and why.
Worked example: say the IF aloud as a sentence and ask what each comma separates.
Practise: ask what the count would be if the rule were >10, and why Bean B changes sides.
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
A student leaves the quote marks off Tall and Short (Sam's mistake). Ask: What does the sheet think Tall is, if it is not in quotes? Fix: Put quote marks around each word.
A student writes > where >= was needed and Bean B comes out Short. Ask: Is 10 more than 10? Which sign includes 10? Fix: Use >= to include the boundary.
A student's COUNTIF shows 0. Ask: Does the rule match what is in the cells, including the quote marks? Fix: Check the spelling of the word and that the rule is in quotes.
A student's IF shows TRUE or FALSE. Ask: How many parts does your IF have? Where are the two answers? Fix: Write =IF(test, answer if true, answer if not).
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
what happens to the count?: Committing to what the count shows after one height changes tests the move: IF and COUNTIF both work again from the new number.
Try: change a height: Changing B2 and watching C2 and B11 settles the prediction: IF decides again, then COUNTIF counts again.
Worked example: decide, then count: Writing the test and the two answers models the move. Sam leaves the quote marks off the words, the mistake planted after the method.
Vary: change the test: Each task changes the rule: a number test, a test on the boundary, then words for the answers.
decide and count: Writing an IF column and a COUNTIF, and counting the other way round.
a quiz result: Building a pass or retry column and two counts for a quiz of their own has students use IF and COUNTIF on their own data.
In your own spreadsheet app: Using IF and COUNTIF in Excel or Sheets shows the same two functions in the real tool.