[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


How do I "separate" PivotTables

Published on
12,306 Points
4 Endorsements
Last Modified:
During the creation of Office 2007, 2010 and 2013, a great emphasis was given to the file size. Of course you would like to make the file size as small as possible and for this purpose even the creation or better yet the behavior of PivotTables has changed since Excel 2003. The PivotTable has always created something called Data Cache based on the data provided. The need for indexing and fast creation of analysis has forced it to work in such a manner. In Excel 2003 each PivotTable had its own Data Cache but now the PivotTable that is created using the same Data Model or Data Source as another PivotTable also borrows that Pivot Tables Data Cache. Therefore, for each new PivotTable analysis that uses the “same” data, Excel saves hard disk space since it does not create its own Data Cache but rather uses the same one as previous PivotTables created on the same Data Model.

While this solution is obviously a great way to save space on the computer, this method also has two quite severe consequences for your PivotTables.

1. Refreshing one individual PivotTable consequently refreshes all PivotTables that are based on the same data, which can be a great thing but you can easily imagine some cases where this would not be such a good thing.

2. The grouping of records within a single field (for example, a Date field that you combine by months or quarters) now cannot be done on an individual PivotTable but immediately effects all the other PivotTables that are related to the same Data Model. If you used this field in another PivotTable, it reflects this grouping instantly. So you’ve lost the ability to group for example a Date field by months in one PivotTable and by Quarters in another.

There are even more ways how sharing a Data Cache effects our analysis but both listed above are reason enough for the need of a “separation” to arise. In fact, In this article we will discuss three different ways how to do this. First way is linked to the creation of the new PivotTable report and tells us how to create a PivotTable in such a way that it already has its own Data Cache and does not share one with the existing PivotTables. Afterwards I will give you two methods on how to “separate” PivotTables that have already been created...

Method 1 (creating a separate PivotTable report)

If you want to create a new PivotTable so that its Data Cache is separate from the other PivotTables you might have, then you must create it in a particular way, or better yet with a special command called PivotTable and PivotChart Wizard. This command has been part of Excel for what seems an eternity, however since by default it is not on any of the ribbons, you have to add it to the Quick Access Toolbar. To do this, you go to File (file)/Options (options), and then Quick Access Toolbar. Above choose Commands Not in the Ribbon
On the left side, find the PivotTable and PivotChart Wizard and with the Add button add the commands to the Quick Access Toolbar.

Afterwards we click in our data and run the command from the Quick Access Toolbar. This will sent us on a very familiar path...
PivotTable and PivotChart Wizard
The first step is more or less self-explanatory, but the second one is very important, since it’s the step where we mark the area with the data for the the analysis.
As soon as you say Next, get the following (important!) notice
Separate a PivotTable
If you select Yes, then the PivotTable will be calculated on the same Data Cache as preexisting PivotTables and it will suffer from all the symptoms described above. If you select No, then you will create a new Data Cache for this PivotTable and therefor it will be separate from the preexisting PivotTables!

Method 2 (manual creation of a separate Data Cache for preexisting PivotTables)

The method is quite simple. Select the PivotTable that you would like to "branch off" and cut it from the workbook and paste it into a new one. Then you only have to copy it back. Sometimes this is enough, but sometimes you have to close the first workbook and save the new workbook, and then open it again and copy the PivotTable back into it.

Method 3 (“separation” of already created PivotTables with the help of VBA code)

The following VBA code does the trick for all the PivotTables in your Workbook.

Sub DataCache()
Dim PivTbl As PivotTable
Dim ws As Worksheet
Dim wsTemp As Worksheet
Dim pt As PivotTable

For Each ws In ActiveWorkbook.Worksheets

For Each PivTbl In ws.PivotTables

c = PivTbl.RowRange.Column
r = PivTbl.RowRange.Row
Cells(r, c).Select

        Set wsTemp = Worksheets.Add
        	ActiveWorkbook.PivotCaches.Create( _
            	SourceType:=xlDatabase, _
           	SourceData:=pt.SourceData).CreatePivotTable _
            	TableDestination:=wsTemp.Range("A3"), _
        	pt.CacheIndex = wsTemp.PivotTables(1).CacheIndex
        Application.DisplayAlerts = False
        Application.DisplayAlerts = True
End If

        Set pt = Nothing

Next PivTbl
Next ws
End Sub 

Open in new window

1 Comment

Expert Comment

Great article but the vba has an error in it.   There is an End IF with no if statement.

Featured Post

CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
A query can call a function, and a function can call Excel, even though we are in Access. This is Part 2, and steps you through the VBA that "wraps" Excel functionality so we can use its worksheet functions in Access. The declaration statement de…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month