Confident CellsExcel practice Start free

PivotTables: clean data before you pivot: practice exercises

Spaces that make two of an item, Find and Replace, TRIM, numbers stored as text, Convert to Number, VALUE, a missing heading, data in two places. 7 exercises on real-looking data, each checked as you go. The full lesson is part of Pro.

The keys

What it doesWindowsExcel for Mac
Find and ReplaceCtrl+HControl+H

All the shortcuts in one list, with Windows and Mac keys side by side.

In the lesson

This lesson has a PivotTable builder like Excel's: drag fields into Rows, Columns and Values, and each task is checked as you go.

Open the PivotTables: clean data before you pivot lesson

How it works

A PivotTable is only as good as its data. A space after a name ("East ") makes a second East. Numbers stored as text make Excel count a column instead of adding it up. A column with no heading stops Excel making the PivotTable at all, and data in two places leaves half of it out.

Fix the data, not the PivotTable: Find and Replace (Ctrl+H) or TRIM for spaces, Convert to Number or VALUE for numbers stored as text, then Refresh. A PivotTable never changes until you do.

=TRIM(C2) =VALUE(D2)

A space you can't see

Three rows say East and one says "East ", with a space at the end. To Excel they're different, so the PivotTable shows East twice: £2,400 and £600.

Row LabelsSum of Sales (£)
East2400
East 600
North3100
Grand Total6100

Fix the data, then Refresh, and it's one East: £3,000.

  • Find and Replace (Ctrl+H): Find what "East " (type the space), Replace with "East", tick Match entire cell contents, Replace All.
  • With many different spaces, add a helper column, =TRIM(C2) filled down, and use that column in the PivotTable (Change Data Source to take it in).

Capitals don't matter: "east" and "East" are the same item. Spaces do.

Numbers stored as text

Five sales: £450, £300, £120, £80 and £50, which add up to £1,000. One of them came in as text, so Excel's PivotTable shows Count of Sales: 5 instead.

The signs: a green triangle in the cell's corner, the number sitting on the left of the cell, and Count where you expected Sum.

  1. Select the amounts, click the ⚠ button beside them, and choose Convert to Number. (For an export that comes every week, a helper column =VALUE(D2) does the same with a formula.)
  2. Refresh the PivotTable.
  3. Change Count of Sales to Sum in Value Field Settings. Refresh won't do that for you.

Headings, and data in one place

Every column needs a heading. With one empty, Excel says “The PivotTable field name is not valid” and makes nothing. Type the heading in, then try again.

A PivotTable reads one block of data. If January's 12 rows are at the top and February's 10 are lower down, below a gap, a PivotTable of A1:D13 leaves February out. Move February's rows up so they follow on, then Change Data Source to the whole block. Data on two sheets is the same: copy one under the other first.

Best of all, make the data an Excel table (Ctrl+T) before you insert the PivotTable. New rows join the table, and Refresh picks them up.

What you'll practise

  1. The PivotTable lists South twice: some cells say "South ", with a space at the end. Use Find and Replace (Ctrl+H) to change "South " to "South" (tick Match entire cell contents), then Refresh.
  2. Spaces before and after the region names make the PivotTable list some regions twice, and there are too many to fix one at a time. Make a tidy copy: type Region tidy in E1, put =TRIM(C2) in E2 and fill it down to E14. Then Change Data Source to A1:E14, and use Region tidy in Rows instead of Region.
  3. The PivotTable shows Count of Sales (£), not the total, because some amounts are stored as text (they have a green triangle and sit on the left of the cell). Select D2:D11, click the ⚠ button and choose Convert to Number. Then Refresh, and change the value to Sum.
  4. Every amount in column D came from another system as text, and the same export arrives every week. Make a column of numbers with a formula, so next week's can be done the same way: type Sales (number) in E1, put =VALUE(D2) in E2 and fill it down. Then Change Data Source to A1:E13, and show the Sum of Sales (number) for each region in place of the count.
  5. Make a PivotTable at F1 of the total sales for each team. Excel won't make one yet: column D has no heading. Type Sales (£) in D1 first.
  6. The PivotTable was made from Oct's sales, A1:D6. Nov's were pasted lower down, in A9:D12, below a gap, so they're left out. Move them up to sit straight under Oct's (cut, then paste at A7), then use Change Data Source so the PivotTable reads A1:D10.
  7. Two things are wrong with this data: North appears twice in the PivotTable, and Sales (£) is counted, not added up. Fix the data, Refresh, and show the Sum of Sales (£) for each region.

Guides with worked examples: Finding and removing duplicates in Excel · TRIM: removing extra spaces and tidying text · Excel formula not calculating: showing as text, or adding to 0