← Working with data

Put the rows in order

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

A table lists eight animals in the order someone wrote them down. Which lives longest? Which are birds? You could read the whole table, or you could ask the sheet.

This table of animals is in the order it was typed in, not in any helpful order. Mass is in kg and lifespan is a rough figure in years. Below the table are controls to sort it and to filter it.

A B C D
1 Animal Group Mass (kg) Lifespan (years)
2 Mouse Mammal 0.02 2
3 Eagle Bird 5 25
4 Goldfish Fish 0.1 10
… … … … …
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.

Who comes first?

You sort the whole table by the Lifespan column, from high to low. Which animal is in row 2, just under the headings?

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

Try: sort the table

Was your guess right? Read across the Tortoise's row: it still says Reptile and 50 kg. Sorting moved the whole row, not just the lifespans.

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

Choose D in 'Sort by', then High to low in 'Order', then click Sort.

Another hint

Read across the Tortoise's row. Is its mass still 50?

Sort the table so the animal that lives longest is at the top.

Use the board. This ticks when you get there.

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

Worked example: sort, then filter

Worked exampleBefore each step, say what you think comes next.
  1. Sort by Lifespan, high to low\text{Sort by Lifespan, high to low}The sheet puts the rows in order of the lifespan column, biggest first.

Now: what happens to the rows?

What does sorting the table by Lifespan do to the rows?

After Sam's sort, the Tortoise shows a lifespan of 2 years. Click the line where Sam first goes wrong.

You filter the table to show only the Birds. What has happened to the other rows?

ModifyChange the problem on purpose and see what happens.

Vary: change the question

You want the heaviest animal first. Which sort do you choose?

The lifespans are 2, 25, 10, 15, 8, 80, 60 and 20. You filter to show only the animals whose Lifespan is more than 20. How many rows are shown?

You filter to show only the Mammals, then sort by Mass from high to low. Which animal is at the top of the rows you can see?

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

Ask the table

Need a hint?

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

Choose C in 'Sort by' and Low to high in 'Order', then click Sort.

Need a hint?

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

In 'Show rows where' choose B, then 'is', then type Mammal and click Filter.

Need a hint?

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

First filter the Group column for Mammal. Then sort by Mass, High to low.

Try it yourselfYour edits are saved in this browser.
You filter to show only Birds and the sheet says Showing 2 of 8 rows. Where are the other six rows?

Sort the table so the lightest animal is at the top.

Use the board. This ticks when you get there.

Show only the mammals.

Use the board. This ticks when you get there.

Show only the mammals, with the heaviest at the top.

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.

Answer a question

Which bird is at the top? Write down the answer in your own words, and say which two steps found it.

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

Filter the Group column for Bird. Then sort by Lifespan from high to low. Read the top row.

Another hint

Two birds are shown, so the one at the top lives longest.

Which bird lives longest? Show only the birds, with the longest-lived at the top.

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 sort and filter. Select the whole table, headings included, and find Sort and Filter under the Data menu. If the headings end up sorted with the data, tick the option that says your data has a header row. Hidden rows are not deleted: clear the filter to see them again.

Now you can
Next lesson8. Choose a chartA chart should answer a question. A column chart compares amounts in separate groups, a line chart shows how something changes over time, a scatter chart shows whether two measurements go together, and a pie chart shows parts of one whole. A reader also needs a title and axis titles that say what is measured and in what units.
For teachers

Students sort a table by one column and filter it to the rows that match a rule, learning that sorting moves whole rows, filtering only hides, and both work on the whole table. They answer questions about eight animals from Year 7 classification, 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: sort by D, high to low, then read across a row.

The one idea: sorting reorders whole rows by one column; filtering hides the rows that do not match. Neither changes the data. Students do not need the Data menu names yet.

The sheet on the page always sorts the whole table below its heading row, as a real app does when the whole table is selected. The mistake in Sam's story is what happens in a real app when only one column is selected.

Filtering here is 'show rows where a column is, is not, is more than or is less than a value'. In Excel and Sheets, filters are drop-down menus on the heading row; the idea is the same.

Be careful with sorting a table that has formulas in it: a formula that uses another row (such as =B3-B2) can give a different answer after a sort. The sheet moves a formula with its row, so a formula that uses its own row keeps working. That is worth saying out loud in a real app.

Running the lesson

  1. Predict: students who chose Elephant think 'longest' means 'biggest'. Ask which column was sorted.
  2. Try: ask what the Tortoise's group and mass are after the sort.
  3. Worked example: ask what Sam would see if only the lifespans moved, and why that is worse than a mistake you can see.
  4. Practise: ask how many rows are shown, and where the others went.
  5. Own app: walk round. Common slips: only one column selected, and a header row sorted into the data.

The hard part (on purpose)

Believing a sort only moves the column you clicked in. In real apps, selecting just one column can sort only that column. Let students read across a row after a sort to check the row still makes sense.

When students get stuck

Stretch and support

Stretch: How would you find the three heaviest birds if there were many more rows? Which tool do you use first, sort or filter, and does the order matter?

Support: A card: Sort reorders whole rows by one column. Filter hides the rows that do not match. Select the whole table first.

Where it leads

Next in Working with data: Choose a chart (column, line, scatter and pie).

Science: classification (Year 7). Data check: lifespans and masses are rough figures for teaching. Use your own class data if you have it.

What each step is for