Sub topic 18
Troubleshooting blank cells, text numbers and stale results
This chapter assumes you can build a PivotTable from a range or an Excel Table, place fields in the Rows, Columns and Values areas, and refresh a PivotTable. Most PivotTable problems come from the source data or from a stale cache. This chapter gives you a working model of both, then covers the three most common symptoms.
The working model: the pivot cache
A PivotTable does not read your worksheet cells directly. When you create it, Excel copies the source data into a hidden store called the pivot cache. The PivotTable summarises the cache. Changing a cell in the source does not change the cache until you refresh.
This explains most "wrong numbers" reports. Either the cache is out of date, or the cache holds data that is not shaped the way you assumed.
Diagnosing by symptom
| Symptom | Likely cause | First check |
|---|---|---|
| Values show Count instead of Sum | A text value or blank cell in the numeric column | Look at the Values field name |
| Totals are lower than expected | Numbers stored as text are ignored by Sum | Check cell alignment and the green triangle |
| Row shows "(blank)" | Empty cells in a row or column field | Scan the source column |
| New rows are missing | Range did not grow, or no refresh | Check the data source range |
| Old values persist after an edit | PivotTable was not refreshed | Use Refresh |
| Field is missing from the field list | Header cell is empty | Check row 1 of the source |
Blank cells
Blanks cause trouble in three different places.
Blanks in row or column fields
If a Region cell is empty, the PivotTable groups those records under (blank). This is correct behaviour, but it usually signals missing data. Fix the source, then refresh. If you only want to hide the group, open the filter drop-down on the field and clear the (blank) check box.
Blanks in the value column
When a numeric column contains an empty cell, Excel normally still picks Sum if the other cells are numbers. The default switches to Count when the column contains any text, and empty cells can be read that way in some datasets, such as those exported from other systems with cells that look empty but hold a space or an empty string. Always check the name of the value field. Count of Sales where you expected Sum of Sales is a strong sign of text in the column.
Blank cells inside the PivotTable body
An empty cell in the grid means no source record exists for that row and column combination. It is not an error. To show a zero instead, right-click the PivotTable, choose PivotTable Options, and on the Layout & Format tab enter 0 in the box labelled "For empty cells show".
Missing headers
Every column in the source needs a header. If a header cell is empty, Excel stops with an error that the field name is not valid when you create the PivotTable. If you add a column to an existing source and leave its header empty, the column will not appear as a field. Fill in a unique name for every header. Duplicate headers are renamed by Excel with a numeric suffix, such as Sales2, which is easy to misread.
Text numbers
A text number is a value that looks like a number but is stored as text. Sum ignores text, so the PivotTable total comes out too low or shows Count.
How to recognise them
- The cell content is left-aligned while real numbers are right-aligned by default.
- A small green triangle appears in the cell corner.
- The Number Format box shows Text.
=ISTEXT(E2)returns TRUE.
You can test an entire column at once. The formula below counts how many cells in the Sales column of a sample range are text. Any result above zero means the column has a problem.
=SUMPRODUCT(--ISTEXT(E2:E500))How to fix them
- In the source, select the column.
- Set the number format to General or Number.
- Convert the values. Setting the format alone does not convert existing text. Use Data, Text to Columns, and choose Finish on the first step. Alternatively, type
1in a spare cell, copy it, select the text numbers, and use Paste Special, Multiply. - Refresh the PivotTable.
- If the value field still says Count, change it: right-click a value, choose Summarize Values By, then Sum.
Excel remembers the summary function you chose, so you must change it by hand after the data is fixed. A formula can also repair the column in a helper column:
=VALUE(TRIM(E2))TRIM removes extra spaces. Non-breaking spaces from web pages are not removed by TRIM. Replace them first with SUBSTITUTE(E2,CHAR(160),"").
Dates behave the same way. Dates stored as text will not group by month or year. If the Group option is greyed out or returns an error that the selection cannot be grouped, check the date column for text values and blanks.
Stale results
Stale results mean the PivotTable shows old data. There are two separate causes, and they need different fixes.
Cause 1: no refresh
Editing source cells does not update the PivotTable. Refresh it by right-clicking and choosing Refresh, or use PivotTable Analyze, Refresh. Refresh All updates every PivotTable and data connection in the workbook. Excel can also refresh when the file opens. Enable this under PivotTable Options, Data tab, "Refresh data when opening the file".
If you want this to happen with one command, use a macro:
Sub RefreshAllPivots()
ThisWorkbook.RefreshAll
End SubCause 2: the source range did not grow
If the source is a plain range such as A1:E6 and you add a seventh row, a refresh still reads only A1:E6. The new record never appears. There are two fixes.
- Convert the range to an Excel Table before creating the PivotTable. A Table expands as you add rows, and a refresh picks up the new rows.
- For an existing PivotTable, choose PivotTable Analyze, Change Data Source, and enter the larger range or the Table name.
Old items that will not go away
After you change a value in the source, the old value may still appear in filter drop-downs, even though no record uses it. This is because the cache keeps deleted items by default. To clear them, open PivotTable Options, Data tab, and set "Number of items to retain per field" to None. Then refresh.
Values that look wrong but are current
Not every surprise is stale data. Before you assume a refresh problem, check these:
- A filter or slicer is limiting the rows shown.
- A field is set to Show Values As, such as percent of column total, and the cells show a percentage instead of a total.
- A calculated field computes on summed totals.
=Sales/Unitsdivides the total sales by the total units, not an average of row-level ratios. - Two PivotTables built separately keep separate caches, so refreshing one does not refresh the other. Refresh All handles this.
GETPIVOTDATA after a refresh
A GETPIVOTDATA formula returns #REF! when the item it names is no longer visible in the PivotTable, for example because a filter removed it or the layout changed so that the field is not displayed. Check that the field and item are shown.
=GETPIVOTDATA("Sales",$A$3,"Region","West")A troubleshooting checklist
- Check that row 1 has a unique header in every column.
- Check that each numeric column contains only numbers.
- Check that each date column contains real dates.
- Check that the data source range covers all rows, or use a Table.
- Refresh the PivotTable.
- Check the summary function on each value field.
- Clear filters and slicers to compare totals.
Exercise
A PivotTable shows "Count of Sales" with a total of 5, but the Sales column contains five amounts, and you expected "Sum of Sales". You also added a sixth row to the source range A1:E6 yesterday and it does not appear. What are the two separate problems, and how do you fix each?
Show answer
Problem 1: at least one Sales value is stored as text, so Excel defaulted to Count. Find it with =SUMPRODUCT(--ISTEXT(E2:E500)), convert the values to numbers (Text to Columns or Paste Special, Multiply), refresh, then change the value field to Sum with Summarize Values By. Problem 2: the source is a fixed range that did not grow. Convert the data to an Excel Table, or use Change Data Source to enter the larger range, and then refresh.
Exercise
A date field will not group by month. Name two causes in the source column and the first step to confirm them.
Show answer
The date column contains blank cells or dates stored as text. Scan the column for empty cells and for left-aligned values or green triangles, or test with =ISTEXT on a cell. Fix or remove those cells, refresh, and group again.