Start studying
Module 6 · Data Wrangling Module contents
Module 6  ·  Card 2 / 14beginner

Pivot Tables

A pivot table summarises a long table by grouping its rows and calculating a total for each group.

You choose which column becomes the rows, which becomes the columns, and which values to add up.

For example, a sales list becomes a grid with products down the side, months across the top and revenue in each cell.

Dragging a different column into place gives a new summary in seconds, without writing a formula.

A pivot table only summarises; the original rows stay exactly as they were.

Learn in depth ↓
Module 06 · Data Wrangling · 14 concepts
In depth  /  15 lines

Pivot Tables, in more detail

A pivot table is the spreadsheet version of grouping and totalling, the same idea as GROUP BY in SQL.

It exists because summary questions come up far more often than questions about single rows.

Most of what a manager asks for is a total, a count or an average broken down by something.

Building one starts with a clean table: one header row, one row per record, no blank rows and no merged cells.

You then place columns into four areas: rows, columns, values and filters.

The values area needs a calculation, usually a sum, though count, average, minimum and maximum are common too.

A filter limits the whole table, for example to one year, without deleting anything.

Totals for each row and column are added automatically, along with a grand total.

Grouping dates by month or quarter is usually one setting rather than a new column.

In some programs a pivot table must be refreshed by hand after the source data changes.

Count and sum are easy to confuse: counting sales gives the number of orders, while summing gives revenue.

Blank cells or numbers stored as text in the value column can quietly change the totals.

A pivot table is the fastest way to answer a breakdown question that is asked once.

When the same breakdown is needed every week, the steps are usually moved into SQL or code.

The same idea appears in pandas later in this module, where it is called groupby or pivot_table.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
A manager has 20,000 orders, each with a region, a month and a sale amount, and wants total sales for each region in each month. What is the quickest route in a spreadsheet?
Data Wrangling

14 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close