Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AC 2.3: Summaries with SUMIFS, COUNTIFS and pivot tables

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

65 minutes

Totals for every day and payment

The shop tallies each sale on a long list. The manager wants a small grid: one row for each day, one column for each way to pay, and the items sold in every box.

Adding by hand is slow. Summary formulas do it in a flash.

Key words

WordWhat it means
COUNTAcounts the cells in a range that are not empty
COUNTIFScounts the rows that pass two or more tests
SUMIFSadds a column for only the rows that pass two or more tests
Pivot tablea grid that summarises a long list, with one field down the side and one across the top
Summaryone number that stands for many rows, such as a total or a count
Databasean organised store of tables that you can ask questions

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can use COUNTA, COUNTIFS, SUMIFS and a pivot table idea to summarise a list.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

No spreadsheet or pivot table here

Important

This platform has no spreadsheet program. Here the cells are a table and the formula is shown as text. You do the same job with code. On site you use a real spreadsheet program. A pivot table is shown as a result grid made with DuckDB.

The tally list as cells

RowA dayB paid byC items
1Moncard3
2Moncash2
3Tuecard1
4Tuecard4
5Wedcash5
6Wedcard2
7Wedcash1

The cells students fill in are left blank in this preview.

Three summary formulas

FormulaDoesAnswer
`=COUNTA(A1:A7)`Counts cells that are not empty7
`=COUNTIFS(A1:A7,"Tue",B1:B7,"card")`Counts rows with Tue and card2
`=SUMIFS(C1:C7,A1:A7,"Tue",B1:B7,"card")`Adds items for Tue and card5

The cells students fill in are left blank in this preview.

Try it: the same summaries in SQL

Code: duckdb
SELECT COUNT(day) AS counta FROM tally;

SELECT COUNT(*) AS countifs
FROM tally WHERE day = 'Tue' AND paid_by = 'card';

SELECT SUM(qty) AS sumifs
FROM tally WHERE day = 'Tue' AND paid_by = 'card';

A pivot table is a grid of summaries

A pivot table turns the long list into a small grid. Days go down the side. Ways to pay go across the top. Each box is a summary of the rows that fit, here the sum of items.

In a spreadsheet you drag fields into rows, columns and values. In DuckDB you write PIVOT.

The lesson goes on

7 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.