How to Clear Pivot Table Cache?

When we edit the source data of a Pivot Table, it will not automatically update in our Pivot Table.

When we create a Pivot Table, Excel creates a replica of the source data. We call this the Pivot Cache. Even though you can’t see it, it’s a component of the Pivot Table.

When we make updates to the Pivot Table, it will use the Pivot cache instead of the original data source. Because of this, pivot tables operate very quickly. As a result, it can quickly summarize all of the data, even if it has thousands of rows.

When we need to update the Pivot Table based on changed source data, we have to clear the Pivot Table cache.

Clearing the Pivot Table cache is not the same as refreshing a Pivot Table. When you refresh a Pivot Table, Excel will update the Pivot Table based on updated data in your source data. But, when you clear the cache of the Pivot Table, Excel will rebuild your Pivot Table from scratch.

In this article, I will show you different methods you can use to clear Pivot Table cache, as well as useful tips to refresh Pivot Tables after clearing the Pivot Table cache.

Method 1 – Use the Pivot Table Options to Clear Pivot Table Cache

We can use the Excel Pivot Table Options to clear the Pivot Table cache.

From the source data on the left side of the below image, I constructed the pivot table on the right.

Pivot Table and Source dataset

Later on, I removed Ben’s name from the list. Since he was the only representative of Australia, the Pivot Table should, in theory, update Australia’s count to zero, or Australia should be deleted.

Removed one record from source dataset

But you can see that my pivot table still lists Australia and that its count remains at 1.

The reason for this is that Pivot Table refers to the Pivot Cache.

Now, in order to update the pivot table, we need to clear the pivot cache.

To clear the cache in your Pivot Table, use the following method:

  1. Select any cell within your Pivot Table. In this case, I have selected cell D3. But you can select any cell in the D1 to E5 range.
Select any cell within Pivot Table
  1. Right-click and select “PivotTable Options.”
select PivotTable Options
  1. In the “Pivot Table Options” Dialog box, go to the Data tab.
go to the Data tab
  1. In the dropdown for “Number of items to retain per field,” select “None.”
Number of items to retain per field select None
  1. Click “OK” and don’t forget to refresh the Pivot Table.
Click OK and refresh

This will clear the cache and prevent old items from being displayed in your Pivot Table fields.

To refresh your Data set you can use any of the below methods.

Method 1 – Use the Pivot Table Options to Refresh Pivot Table

  1. Select any cell on our Pivot Table to activate the “PivotTable Analyze” tab.
activate the PivotTable Analyze tab
  1. Click the “Refresh” Button on the “Data” group of the “PivotTable Analyze” tab.
Click the Refresh Button

As soon as we click on the “Refresh” button, Pivot Cache will clear. Then, Excel will update the Pivot Table based on our source data.

Now, in this example, after we click the “Refresh” button, Excel will remove Australia from the Pivot Table.

Australia removed from the Pivot Table

We have another method by which we can refresh and clear the pivot cache of our pivot table.

First, right-click the pivot table and choose “Refresh” from the context menu.

Refresh the Pivot Table
Also read: How to Change Data Source in Pivot Table

Method 2 – Use the Excel “Refresh” Shortcut to Refresh the Pivot Table

We sometimes like to use Excel shortcuts instead of going to tabs and clicking on icons. We can refresh the Pivot Table using an Excel shortcut too.

I created the Pivot Table on the right side of the image below using the source data on the left side.

Pivot Table and Source dataset

Later, I removed Ben’s name from the list.

The Pivot Table needs to, in theory, update Australia’s count to zero or remove Australia because Ben was the only person from Australia.

Removed one record from source dataset

But as you can see, Australia is still shown in my pivot table with a count of 1, and it remains to be shown.

The reason for this is that Pivot Table is referring to Pivot Cache. To update the pivot table, we have to refresh the pivot table.

To quickly refresh the Pivot Table in Excel, use the shortcut given below.

ALT + F5

You have to use the above keyboard shortcut as follows.

  1. Select any cell of the Pivot Table.
  2. Hold down the ALT key and then press the F5.

Sometimes ALT + F5 fails to work on your computer. It happens when you lock the function keys. In that case, in addition to pressing F5, you have to press the Fn key on your keyboard. After that, the keyboard shortcut will work for you.

Also read: Cannot Group That Selection Error in Pivot Tables

Method 2 – Use a VBA Code to Clear Pivot Table Cache

Consider a scenario in which you produced an Excel report or an Excel template with several pivot tables for someone else.

Then you have to give a user-friendly method for clearing the Pivot Table cache and updating Pivot Tables.

From the source data on the left side of the figure below, I constructed the pivot table on the right.

Pivot table and source dataset

Now I want to send the above worksheet to someone else. I need to come up with a simple way to update and clear the pivot table for him because he is not familiar with Excel.

So, in this case, the best option is to write VBA code and link it to a button.

We can do that by using the VBA code below.

'Code developed by Steve Scott from https://spreadsheetplanet.com

Sub ClearCache()

    'Loop through each PivotCache object in the PivotCaches collection of the active workbook
    For Each PivotCache In ActiveWorkbook.PivotCaches

        'Call the Refresh method on the current PivotCache object to refresh the associated PivotTable data
        PivotCache.Refresh

    'Move on to the next PivotCache object in the collection
    Next PivotCache

End Sub

You can follow the below steps for that.

  1. First, press ALT + F11 to open the VBA Editor.
VB Editor
  1. Expand the “Insert” menu and select “Module”.
Insert a module
  1. Then, copy and paste the above VBA code.
Copy Paste code in module
  1. Click the “Save” button.
Save the code in VB Editor
  1. Click “No” in the pop-up box and save the workbook as an Excel Macro-Enabled Workbook (*.xlsm).
Click on No

Now you have saved the VBA code to your Excel workbook.

Let me now also show you how to add a button in the worksheet so that you can click that button and clear the Pivot Cache right away.

  1. Insert a shape in the worksheet by following the below steps in the given sequence.

Insert tab >> Illustrations >> Shapes>> Rectangle

  1. Next, type “REFRESH” inside the shape.
Add a refresh button
  1. Right-click on the shape and click “Assign Macro”.
Assign macro to the button
  1. Finally, select “ClearCache” from the macro name box and click the “OK” button.
Select the macro to run

Now, we can just click the “REFRESH” button to clear the “Pivot Table Cache”.

click the REFRESH button to clear the Pivot Table Cache
Also read: How to Group by Months in Excel Pivot Table?

Benefits of Clearing Cache of Pivot Tables

Clearing the cache of a Pivot Table has several benefits, such as:

  1. Improved performance: Clearing the cache can free up memory resources, leading to faster calculations and overall improved performance of the workbook.
  2. Reduced file size: Clearing the cache can decrease the overall size of the Excel file, making it easier to share and store.
  3. Accurate data: Clearing the cache ensures that your Pivot Table displays the most up-to-date data, avoiding potential discrepancies or outdated information.
  4. Elimination of redundant data: Removing the cache helps to get rid of any unnecessary or redundant data that may have been stored in the Pivot Table.
  5. Efficient memory usage: Clearing cache enables more efficient usage of system memory, allowing Excel to allocate resources to other tasks or processes.
  6. Enhanced stability: By freeing up memory resources, clearing cache can also reduce the chances of Excel crashing or becoming unresponsive due to heavy data processing.
  7. Easier troubleshooting: If you encounter any issues with your Pivot Table, clearing cache can be a helpful step in diagnosing and resolving the problem.

In this article, you learned two different methods to clear the Pivot Table cache.

You can choose the way that works best for you out of the three that all perform the same task.

Other Excel articles you may also like:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.

Leave a Comment