Create a PivotTable to analyze data in multiple tables

 Important    This feature isn’t available in Office on a Windows RT PC. Want to see what version of Office you're using?

If your business stores its important data in relational databases, chances are you analyze and report on that data on a regular basis. When your data happens to be relational, you can build a PivotTable like this in minutes:

PivotTable containing multiple tables

What’s different about this PivotTable? Notice how the Field List shows a collection of tables, each one containing fields that you can combine in a single PivotTable to slice your data in multiple ways. No manual formatting or data preparation is necessary. If you have relational data, you can immediately build a PivotTable based on related tables as soon as you import the data.

How do you get multiple tables into a PivotTable Field List? There are two ways. First, when you import from a relational database, you can import multiple tables simultaneously. Alternatively, you can also import tables individually from the same or different data sources, add them to a Data Model in Excel, create relationships, and then use that Data Model to drive a PivotTable.

Let’s take a look at how you would import multiple tables from SQL Server.

  1. Make sure you know the server name, database name, and which credentials to use when connecting to SQL Server. Your database administrator can provide the necessary information.
  2. Click Data > Get External Data > From Other Sources > From SQL Server.
  3. In Server Name, enter the network computer name of the computer that runs SQL Server.
  4. In Log on credentials, click Use Windows Authentication if you are connecting as yourself. Otherwise, enter the username and password provided by the database administrator.
  5. In Select Database and Table, choose the database, and then click Enable selection of multiple tables.

Enable selection of multiple tables checkbox

  1. Manually choose the tables you want to work with. Alternatively, pick one or two, and then click Select Related Tables to auto-select tables that are related to those you selected.
  2. If Import relationships between selected tables is checked, keep it that way to allow Excel to recreate equivalent table relationships in the workbook.
  3. Click Finish.
  4. In the Import Data dialog box, choose PivotTable Report.

Import options dialog box

  1. Click OK to start the import and populate the Field List.
  2. Notice that the Field List contains multiple tables. These are all of the tables that you selected during import. You can expand and collapse each table to view its fields. As long as the tables are related, you can create your PivotTable chart by dragging fields from any table to the VALUES, ROWS, or COLUMNS area.

PivotTable Fields list

  1. Drag numeric fields to the VALUES area. For example, if you are using an Adventure Works sample database, you might drag SalesAmount from the FactInternetSales table.
  2. Drag date or territory fields to the ROWS or COLUMNS area to analyze sales by date or territory.
  3. Sometimes you need to create a relationship between two tables before you can use them in a PivotTable. If you get a message indicating a relationship is needed, click Create to get started.

Create button appears when relationship is needed


 Notes 

Other ways to analyze multiple tables

Relational databases are not the only data source that lets you work with multiple tables in a PivotTable Field List. You can use arbitrary tables throughout your workbook, or import data feeds that you then integrate with other tabular data in your workbook. To make all this unrelated data work together, you’ll need to add each table to a Data Model, and then create relationships between the tables using matching lookup values.

Start a new PivotTable using tables in a Data Model

Perhaps you’ve related several tables, creating a Data Model in the process, and are now ready to use this data in your analysis. Here is how you start a new PivotTable or PivotChart using the Data Model in your workbook.

  1. Click any cell on the worksheet.
  2. Click Insert > PivotTable.

PivotTable button on the Insert tab

  1. In the Create PivotTable dialog box, under Choose the data that you want to analyze, click Use an external data source.

Create PivotTable dialog box with use and external data source selected

  1. Click Choose Connection.
  2. On the Tables tab, in This Workbook Data Model, select Tables in Workbook Data Model.
  3. Click Open, and then click OK to show a Field List containing all of the tables in the model.

More about PivotTables and Data Models

 
 
Maikakapit sa:
Excel 2013