Sub topic 14
Troubleshooting Common Problems
This chapter assumes you can build a basic PivotTable, you know the difference between text values and true dates in Excel cells, and you have inserted at least one slicer and one timeline. It covers the faults that come up most often and how to find the cause of each one. Work through the checks in the order given. They go from the most common cause to the least common.
A Method for Diagnosing Problems
Most slicer and timeline faults come from one of three places:
- The source data, such as text that looks like dates, or blank cells in a date column.
- The pivot cache, which is the stored copy of the data that a PivotTable reads from. Controls can only connect PivotTables that share one cache.
- The control settings, such as a hidden item, a sort order, or a connection that is not ticked.
Ask which of the three is involved before you change anything. That avoids rebuilding a report that only needed one box ticked.
The Timeline Is Disabled or Cannot Be Inserted
The Insert Timeline button is greyed out, or Excel shows the message "Cannot create a timeline from this selection." A timeline needs a field whose values are all true dates. Check these causes in order.
- The field holds text, not dates. Dates imported from a CSV file or pasted from another system are often stored as text. They are usually left-aligned in the cell, and the number format shows General or Text. Select the column, then use Data > Text to Columns > Finish, or multiply the cells by 1 in a helper column. Then confirm that the cells right-align.
- The date column contains blanks or non-date entries. One cell with "n/a" or a blank is enough to break the field. Fill the cells with a valid date, or remove those rows from the source.
- You selected a field that is not a date. The timeline dialog lists only date fields. If your date is missing, the field is not recognised as a date.
- The date field is grouped. In some versions, a date field that Excel has already grouped into Years, Quarters, and Months appears under its original name, but it behaves differently. Ungroup the field first (right-click a date, then choose Ungroup), and then insert the timeline.
- The PivotTable comes from a source that does not support timelines. Timelines need a PivotTable based on a worksheet range, an Excel Table, or the Data Model. They do not work with a PivotTable built on an OLAP cube in some older setups.
After you fix the source, refresh the PivotTable with PivotTable Analyze > Refresh, then try the timeline again.
Checking Dates with a Formula
You can test a column quickly. In a spare cell, enter this formula, where A2:A500 is your date column:
=SUMPRODUCT(--NOT(ISNUMBER(A2:A500)))The result is the number of cells that are not numbers. Excel stores true dates as numbers, so any result above zero points to text or blanks that you need to fix.
A Slicer Does Not List the Second PivotTable
You open Report Connections (right-click the slicer, then choose Report Connections) and the PivotTable you want is not in the list. The list shows only PivotTables that share the same pivot cache as the slicer. There are three common reasons.
- The second PivotTable was built from the same range, but separately. Each time you create a PivotTable from a range using the dialog, Excel may create a new cache. To avoid this, copy the first PivotTable and paste it, or select the first PivotTable's cell when you start the new one. Excel then reuses the cache.
- The two PivotTables come from different source ranges or tables. Controls cannot cross sources. Use one Excel Table, or load both tables into the Data Model and build both PivotTables from it.
- The PivotTable is on a workbook that is closed or a different file. A slicer connects only to PivotTables in the same workbook.
To check which cache a PivotTable uses, run this macro. It prints the cache index for every PivotTable on the active sheet.
Sub ListPivotCaches()
Dim pt As PivotTable
For Each pt In ActiveSheet.PivotTables
Debug.Print pt.Name, pt.CacheIndex
Next pt
End SubPivotTables with the same number in the second column share a cache. If the numbers differ, rebuild the second PivotTable from the first one. Open the Immediate window with Ctrl+G in the VBA editor to read the output.
A Slicer Filters Only Some of the PivotTables
The slicer is connected, but one PivotTable does not respond. Check each of these.
- The connection is not ticked. Open Report Connections and make sure the box next to that PivotTable is checked.
- The PivotTable has a different field. A slicer for Region filters PivotTables that use the Region field from the same cache. The field does not have to be in the layout of each PivotTable, but the PivotTable must be built on that cache.
- The PivotTable has not refreshed. Slicer changes apply immediately, but data changes do not. Use Data > Refresh All.
- Another filter overrides the result. A report filter or a row label filter on the same field in the second PivotTable can combine with the slicer and show an empty or smaller result. Clear the other filter, or accept that the result is the overlap of both.
Items Are Missing, Greyed Out, or Out of Date
Slicer buttons appear in different styles to show their state. A normal button is selected or available. A pale or greyed button means no data matches given the other filters currently active. This is normal behaviour, not a fault.
If an item is missing altogether, work through the following causes.
- New data has not been refreshed. A slicer lists the items stored in the cache. After you add rows to the source, refresh the PivotTable.
- The source range did not grow. If you used a fixed range such as
A1:F500, new rows below row 500 are not included. Convert the source to an Excel Table with Ctrl+T so the range expands automatically. - Old items stay in the list. After you delete data, the slicer may still show items that no longer exist. Open the PivotTable Options (right-click the PivotTable, then choose PivotTable Options > Data) and set Number of items to retain per field to None. Then refresh.
- Items with no data are hidden. Open Slicer Settings (right-click the slicer, then choose Slicer Settings). If Hide items with no data is ticked, items that have no rows in the source disappear. Clear the tick if you want them to stay visible.
Timeline Shows the Wrong Range or Will Not Select a Range
A timeline can show dates you did not expect, or the selection can jump to an unexpected period.
- The time level is wrong. Check the level selector in the top-right corner of the timeline. If it is set to Years, you can select only whole years. Switch to Months or Days for a finer range.
- The selection is a single period. Click one bar to select one period. To select a range, click the first bar and drag the handles on either side, or hold Shift and click the last bar.
- The date range is far longer than the data. A few stray dates, such as 1900 or 2099, widen the scroll bar and shrink the visible bars. Find them by sorting the source column, and correct or remove them.
- The timeline still shows a filter after you clear the slicer. Slicers and timelines are separate controls. Clearing one does not clear the other. Click the Clear Filter icon on each one.
Performance Is Slow
Slow response usually shows up in workbooks with many controls connected to many PivotTables. Each click recalculates every connected PivotTable.
- Reduce the number of connected PivotTables to those the user needs.
- Use one PivotTable per cache where possible, and avoid duplicating a large source.
- Use fewer slicers on fields that have thousands of unique items. A field with a large item count makes the slicer slow to draw. Use a report filter or a timeline for such fields.
- Set Calculation to manual while you change many slicer selections in a macro, then switch it back.
A Slicer Macro Returns an Error
The macros from the VBA chapter fail in a few predictable ways.
| Error | Likely cause | Fix |
|---|---|---|
| Subscript out of range | The slicer cache name in the code does not match the workbook | Check the exact name in **Slicer Settings**, or list names with `For Each sc In ActiveWorkbook.SlicerCaches: Debug.Print sc.Name: Next` |
| Run-time error 1004 on `AddPivotTable` | The PivotTable uses a different cache | Rebuild the PivotTable from the first one |
| Slicer appears in the wrong place | The size and position arguments are in points, measured from the top-left corner of the sheet | Adjust the Top, Left, Width, and Height values |
| `SlicerCaches.Add2` is not found | An older Excel version | Use `SlicerCaches.Add` on Excel 2010 |
Quick Reference
| Symptom | First check |
|---|---|
| Insert Timeline is disabled | Are all values in the date column true dates? |
| PivotTable is missing from Report Connections | Do both PivotTables share one cache? |
| One PivotTable ignores the slicer | Is its box ticked in Report Connections? |
| Slicer item is missing | Did you refresh, and is the source an Excel Table? |
| Deleted item still appears | Set items to retain per field to None |
| Timeline will not select a month | Is the time level set to Months? |
Exercise
A colleague sends you a workbook. The Insert Timeline button is greyed out for a PivotTable on the Sale Date field. The dates are left-aligned in the source column. Name the likely cause, one way to fix it, and one formula that checks whether the fix worked.
Show answer
The dates are stored as text, so the field is not a true date field. Select the column and use Data > Text to Columns > Finish to convert them, then refresh the PivotTable. To check, use =SUMPRODUCT(--NOT(ISNUMBER(A2:A500))) on the date column. A result of 0 means every cell is a real date or number. Blank cells also count as non-numbers, so fill any blanks too.
Exercise
You built two PivotTables from the same table, but the second one does not appear in the slicer's Report Connections list. What do you check, and how do you fix it?
Show answer
Check whether the two PivotTables share a pivot cache, for example by printing pt.CacheIndex for each one in a macro. If the numbers differ, they use different caches. Delete the second PivotTable and recreate it by copying and pasting the first PivotTable, then change its layout. It now shares the cache and appears in the list.