Using a Query as a Pivot Table Data Source
This page shows how a query can serve as the data source for a PivotTable, and why that is worth doing.
Power Query and PivotTables together
Section titled “Power Query and PivotTables together”A PivotTable fed by a query, rather than by a worksheet range, can make a workbook far smaller, and it can still be used when the source data is out of reach.
The example starts with a source workbook, though the source could be anything Power Query can connect to. One worksheet holds 1 million rows of random sales transactions, each with a category, price, cost and margin:

The workbook has no formulas, only data, as if it had been exported from a sales system. It is about 27 MB:

1. Connect with Power Query
Section titled “1. Connect with Power Query”- Create a new, blank workbook, and use Power Query to connect it to the source workbook.
- In the Power Query editor, click Close & Load To, and choose Only Create Connection.
This sets up the connection to the source workbook without bringing any of its data into the new one.

Save the new workbook. It is only 13 KB, which confirms that it holds a connection and no data.

2. Create a PivotTable
Section titled “2. Create a PivotTable”Next, build a PivotTable on the query’s connection.
- On the Insert tab, click PivotTable.
- In the Create PivotTable dialog, select Use an external data source, then click Choose Connection.

The Existing Connections dialog lists the query created earlier.
- Select the query and click Open.

- Click OK to add the PivotTable, and lay it out as needed. In this example it sums price, cost and margin by category:

Saved with the PivotTable, the workbook grows to 536 KB, which is still far smaller than the source.

The PivotTable stores its data in the pivot cache, which is compressed, and only the summary appears on the worksheet. That keeps the file small, and here the new workbook is about 51 times smaller than the original.
3. Use it without the source data
Section titled “3. Use it without the source data”To prove that the new workbook does not read from the source file, move or delete the source file.
The PivotTable still works fully, without access to the source data, because it works from its pivot cache.
The one thing it cannot do, as you would expect, is refresh.
This example follows Matt Allington’s post Traditional Pivot Tables using Power Query – Can Do on Excelerator BI.