Sub topic 2
Preparing source data: one header row, one record per row
A PivotTable is only as reliable as the data behind it. Most PivotTable problems, such as blank labels, numbers that won't add up and fields that split in odd ways, start in the source range. This chapter covers the shape of data a PivotTable expects, the mistakes that break it, and a short checklist to run before you insert one.
This chapter assumes you can navigate workbooks, worksheets, cells and ranges. It also assumes you can enter data and write simple formulas such as SUM. You don't need to have built a PivotTable yet.
The shape a PivotTable expects
A PivotTable reads a rectangular block of cells and treats it as a database table. Two rules define the shape:
- One header row. The first row holds one unique, non-empty name for each column. Each name becomes a field in the PivotTable Fields pane.
- One record per row. Each row below the header describes one event, item or transaction. Each column holds one kind of value for that record.
This layout is called flat, tabular or "long" data. Here is a small example:
Date,Region,Product,Units,Sales
2025-01-05,East,Widget,10,250
2025-01-12,West,Gadget,4,180
2025-02-03,East,Gadget,7,315
2025-02-14,West,Widget,12,300
2025-03-09,East,Widget,5,125Each row is one sale. Date, Region and Product describe the sale, and Units and Sales measure it. The PivotTable can turn any of these columns into row labels, column labels or calculated totals without you reshaping the data.
Dimensions and measures
When you design a source table, it helps to sort each column into one of two roles.
| Role | Purpose | Typical columns | Typical PivotTable area |
|---|---|---|---|
| Dimension | Describes or categorises a record | Date, Region, Product, Customer | Rows, Columns, Filters |
| Measure | A number you add up or average | Units, Sales, Cost | Values |
Any column can sometimes play either role. A column of order IDs is a dimension if you group by it and a measure if you count it. Deciding the intended role helps you keep each column to a single data type.
Common source-data mistakes
The table below lists patterns that break or complicate a PivotTable, and the fix for each.
| Problem | What happens | Fix |
|---|---|---|
| Blank header cell | Excel reports that a field name is not valid, or refuses to create the PivotTable | Give every column a unique name |
| Duplicate header names | Excel renames the second one, for example `Sales2`, which is confusing | Use distinct names such as `Sales` and `Budget` |
| Two or more header rows | The second header row is read as a data record | Merge the labels into one row, such as `2025 Q1 Sales` |
| Merged cells | Only the top-left cell holds a value, so other rows appear blank | Unmerge and fill the value into every row |
| Blank rows or columns inside the data | Excel may stop reading at the gap and select only part of the data | Delete blanks, or use an Excel Table |
| Subtotal or grand total rows | Totals are counted as records and inflate results | Remove them. The PivotTable calculates totals itself |
| Numbers stored as text | Values are counted rather than summed, and sort in the wrong order | Convert them to real numbers |
| Mixed data types in one column | Excel guesses the type from the data, so some values may be ignored | Keep one type per column |
| Dates stored as text | Date grouping is unavailable | Convert them to real dates |
Wide data versus long data
A common trap is a layout with one column per month:
Region,Jan,Feb,Mar
East,250,315,125
West,180,300,0This is easy to read, but a PivotTable sees Jan, Feb and Mar as three separate fields, not as values of a single Month field. You can't group them, filter them as one list, or add a new month without changing the layout. Reshape it so that month becomes a column:
Region,Month,Sales
East,Jan,250
East,Feb,315
East,Mar,125
West,Jan,180
West,Feb,300
West,Mar,0The rule of thumb is that if you would want to filter or group by something, it should be a column, not a column heading.
Cleaning the data
Cleaning is usually quicker than you expect if you follow a set order.
Check for text numbers and text dates
Numbers stored as text often appear left-aligned and may show a small green triangle in the corner of the cell. You can test a column with a helper formula:
=ISNUMBER(E2)FALSE for a cell that looks like a number means it is text. To fix a column, select it, open Data > Text to Columns and choose Finish without changing any options. This forces Excel to re-read each value as a number or date. Alternatively, type 1 in a spare cell, copy it, select the text numbers, use Paste Special > Multiply, and delete the helper cell.
Remove stray spaces
Values such as "East " (with a trailing space) and "East" look identical but become two separate items in the PivotTable. Use a helper column:
=TRIM(B2)Fill it down, copy the results, and paste them as values over the original column. Then delete the helper column. TRIM also collapses repeated internal spaces. It does not remove non-breaking spaces from web data. For those, use =TRIM(SUBSTITUTE(B2,CHAR(160)," ")).
Standardise spelling and case
PivotTables ignore case when they build the list of items, so east and East merge into one item. They do not merge Widget and Widgets, or N. America and North America. Use Data > Filter on each category column and scan the drop-down list for near-duplicates.
Fill blanks in grouped data
Reports exported from other systems often show a category only on the first row of a group. Every row needs its own value. To fill the gaps:
- Select the column and press F5, then Special, then Blanks, then OK.
- Type
=and press the Up Arrow key, which points the active blank cell at the cell above. - Press Ctrl+Enter to apply the formula to all selected blanks.
- Copy the column and paste as values.
Handling blanks in measures
An empty cell in a numeric column is skipped, while a 0 is included. This affects counts and averages. If a missing sale means "no sale", an average of Sales ignores it. If it means "sold nothing", the average should include a 0. Decide which meaning applies and enter it consistently.
Pre-flight checklist
Before inserting a PivotTable, check each of these:
- Row 1 contains a unique, non-blank name in every column.
- No row or column inside the data is entirely empty.
- No merged cells, subtotals or grand total rows are present.
- Each column holds one data type.
- Dates are true dates and numbers are true numbers.
- Category names are spelt and spaced consistently.
- Nothing else sits directly next to the data. Leave a blank column or row between the data and any notes, so Excel does not include them.
Verifying the range
Click any cell in the data and press Ctrl+A. Excel selects the current region, which is the block of cells bounded by blank rows and columns. This is also the range Excel proposes when you insert a PivotTable. If the selection stops short or runs too far, the data has a stray gap or a neighbouring note. Fix that before you continue.
In the next chapter, you convert this range into an Excel Table so that new rows join the PivotTable source automatically.
Exercise
A colleague sends a sheet with the headings Region, Jan, Feb, Mar, plus a bottom row labelled Total. You want to summarise sales by month and by region. Describe the changes you would make before building the PivotTable.
Show answer
Remove the Total row, because the PivotTable would count it as a record and double the totals. Reshape the data from wide to long so that there are three columns: Region, Month and Sales. Each region-month pair becomes its own row. This makes Month a single field that you can put in Rows, Columns or Filters, and you can add new months as new rows. Finally, check that the Sales values are true numbers and not text.
Exercise
A PivotTable shows both East and East (with a trailing space) as separate row labels. Why does this happen, and how do you fix it in the source data?
Show answer
The PivotTable treats text that differs by even one character as different items, and a trailing space is a character. Add a helper column with =TRIM(B2), fill it down, copy it and paste as values over the original column, then delete the helper. Refresh the PivotTable afterwards so the two labels merge.