Contextures

Home > Pivot > Create > Power Pivot

Power Pivot from Identical Structure Excel Files

Microsoft Power Pivot is a powerful data analysis add-in that will let you work with millions of records within the familiar Excel environment. In this tutorial, use it to create a pivot table from multiple files

Select Table to Import

Introduction - Video

Power Pivot for Excel is a powerful data analysis add-in that will let you work with millions of rows of data within the familiar Excel environment. To download the free add-in, go to the Power Pivot page on the Microsoft website.

This video shows the steps for combining data from multiple tables in Power Pivot, and there are written steps below the video.

Pivot Table from Multiple Files

Instead of a single table, you can use Power Pivot to create a pivot table from multiple Excel workbooks or worksheets, by using the Primary and Foreign keys to join the tables. For example, there could be a 'ProductID' field in an Orders table and a PriceList table.

Occasionally you might want to create a pivot table from files where you can't use keys to join the tables. Maybe you have workbooks for different years' sales data, or budget data from several departments.

In this example, we'll combine data from two Excel files. The files have different data, but an identical structure -- sales data for the East and West regions. In this case, we can't use a key to connect the tables; instead, we want to create one combined table from all the data. The following technique allows you to import more than a million records from Excel, despite the fact that one worksheet can only contain up to 1,048,576 rows.

Thanks to Excel MVP, Kirill Lapin, for sharing this very helpful tip with us. You can see more of Kirill's work in the Contextures blog posts on Combining Data from Two Excel Files in a Pivot Table.

Create a Connection in the Workbook

The key to combining data from identical files is to start by creating a workbook connection, before you launch Power Pivot.

  • On the Excel Ribbon's Data tab, click Connections.

    Connections

  • In the Workbook Connections window, click Add
  • At the bottom of the Existing Connections window, click the Browse button (Browse for More).

    Browse for More

  • In the Select Data Source dialog box, navigate to the folder where your files are located. In this example the files are in the C:\_TEST folder
  • Select one of the files that you want to import -- EastSales.xlsx in this example -- and click Open.

    Select Data Source

  • Select a table to import, and click OK.

    Select Table to Import

  • The new connection appears in the Workbook Connections window.

    New Connection

Combine the Data in Power Pivot

  • Close the Workbook Connections window, and on the Ribbon, click the Power Pivot tab.
  • Click Power Pivot Window, to launch the Power Pivot add-in.

    Launch PowerPivot

Note: I was using Windows XP, so the Power Pivot window has a menu bar in the screen shots below. If you're using Vista or Windows 7, you'll see a Ribbon instead.

  • On the Table menu, click Existing Connections, or, on the Ribbon, click Design, then Existing Connections.

    Existing Connections

  • At the bottom of the Existing Connections window, under Workbook Connections, click on the connection that you added, and click Open.

    Open Workbook Connection

  • In the Table Import Wizard, click Next, then select the table, and click Finish

    Table Import Wizard

  • After the data is successfully imported, click Close.

    Table Import Successful

Change the SQL Statement

Now that the first table has been imported, you can change its properties, to combine it with data from the second table.

  • On the Table menu, click Table Properties, or on the Ribbon, click the Design tab, then click Table Properties.

    Table Properties

  • In the Switch To drop down list, , click the arrow, then select Query Editor.

    Select Query Editor

  • Edit the SQL statement, to create a union query, combining the two tables. For this example, the SQL statement is show below.
    • IMPORTANT: The file name is enclosed with accent grave marks (`), NOT apostrophes ('). The accent grave key is above the Tab key on my keyboard -- it might be in a different location on your keyboard.
    SELECT [EastSales$].* FROM [EastSales$]
    UNION ALL
    SELECT * FROM `C:\_TEST\WestSales.xlsx`.[WestSales$]
  • After you change the SQL statement, click the Validate button, to verify that the statement is correct, then click Save.

    Validate SQL

Note: The SQL query string can also be edited in the Excel workbook connection window, but there's no Validate feature there:

  • On the Excel Ribbon, click the Data tab, and click Connections
  • Select the connection you want to edit, and click Properties.
  • On the Definition tab, edit the SQL string in the Command text box.

Create Pivot Table

Now that the data from the two files are combined, you can create a pivot table from the combined data.

  • On the Toolbar, click the Create a PivotTable button, or on the Ribbon, click the Home tab, then click PivotTable.

Create PivotTable

  • Select a location for the pivot table, and click OK.

Select PivotTable Location

  • In the Power Pivot Field List, add  fields to the pivot table layout, to see a summary of the combined data.

    Add Pivot Table fields

Here's the pivot table that was created from the combined data, with columns for the East and West regions. The Report Layout is Tabular, and Number format is used, with thousands separator and zero decimals.

Completed Pivot Table

Get the Sample File

Get the Power Pivot from Identical Workbooks practice files, to test the combine files technique from this page

More Links

Power Pivot Resources

PowerPivot for Excel 2010 Virtual Lab Review

Drill Into Data With PowerPivot

Pivot Table Index

 

 

Last updated: December 9, 2022 7:59 PM