Yes, you can connect multiple data tables in a Pivot Table to create a single report. This creates a data model where one table (the 'lookup' or 'dimension' table) provides labels, while another (the 'fact' or 'transaction' table) provides the numbers. This is essential for reporting on sales by region, products, or employees without duplicating data or creating inconsistent totals.

What You'll Need

  • A dataset with at least two related tables. For example, a 'Sales' table with columns like Order ID, Product ID, and Amount, and a 'Products' table with columns like Product ID, Product Name, and Category.
  • A compatible data source. This works in Microsoft Excel (with Power Pivot enabled) and in Microsoft Power BI Desktop.
  • The ability to add a new sheet or data model. In Excel, this requires the Power Pivot add-in, which is usually included with modern Office versions.

Step-by-Step

  1. Prepare your data. Ensure that the data in your tables is clean and that the column you intend to use for the relationship has unique values in the lookup table. For example, the 'Product ID' column in the 'Products' table must have a unique value for every single row; the 'Order ID' in the 'Sales' table can have duplicates. Blank cells in the key column will break the relationship and cause errors.
  2. Open your data source. Open the file containing your data (an Excel workbook or a Power BI file). In Excel, go to the 'Power Pivot' tab in the ribbon and click on 'Manage Data Model'. In Power BI Desktop, the Data Model tab will already be open.
  3. Add the tables to the model. In the 'Tables' pane on the left side of the window, you will see a list of tables. If a table is not listed, click the 'Add Table' button and browse to select the Excel file or database that contains it. The table will now appear in the list.
  4. Identify the relationship. Look at the two tables you want to connect. Find the column in each table that contains the same type of information. These are your 'keys'. For instance, 'Product ID' in the 'Sales' table and 'Product ID' in the 'Products' table.
  5. Create the relationship. In the diagram view of the data model, click and drag from the 'Product ID' column in the 'Sales' table to the 'Product ID' column in the 'Products' table. A line will connect the two tables, indicating a relationship. Alternatively, you can right-click on one table, select 'Create Relationship', and choose the tables and columns from the dropdown menus.
  6. Verify the direction. The arrow on the relationship line should point from the 'Sales' table to the 'Products' table. This is because the Sales table contains the transactional data (facts), and the Products table provides the descriptive data (dimensions). The arrow direction is important for how the data will be calculated.
  7. Refresh your Pivot Table. Go back to your main Excel sheet where your Pivot Table resides. Right-click on the Pivot Table and select 'Refresh'. The Pivot Table should now display data from both tables, combining the information based on the relationship you created.

Common Mistakes

One of the most frequent errors is attempting to create a relationship between tables that do not share a common field. For example, trying to join a 'Sales' table to a 'Customers' table using their full names or addresses. This will fail because names and addresses are rarely unique identifiers. Always use a unique ID, such as a Customer ID or Order ID.

Another mistake is placing the Pivot Table on the same sheet as the raw data. This can cause the Pivot Cache to become corrupted, leading to errors when trying to refresh the data or create relationships. It is best practice to create a dedicated sheet for your Pivot Tables and place them at least one sheet away from the source data.

Tips

When naming your tables in the data model, use a clear and consistent naming convention. Instead of 'Table1' or 'Sheet1', name them 'Sales_Data', 'Product_Master', or 'Employee_Information'. This makes it much easier to understand which table is which when you are building complex models.

Always check the 'Cardinality' setting when creating a relationship. The default is 'One-to-One' or 'One-to-Many'. For a standard sales report, the relationship will almost always be 'One-to-Many' (one product is sold in many orders). Incorrect cardinality can lead to incorrect calculations, such as doubling your sales figures.

Troubleshooting

If your Pivot Table is not showing the expected data after creating a relationship, the first thing to check is the relationship arrow. If the arrow is pointing in the wrong direction, the Pivot Table will not be able to find the matching data. To fix this, right-click the relationship line and select 'Reverse Direction'. This switches the arrow so it points the correct way.

If you see an error message like 'The relationship could not be created because the cardinalities are not compatible', you likely have a data type mismatch. For example, the 'Product ID' in the Products table might be set as text, while the 'Product ID' in the Sales table is set as a number. You must go to the Data Types tab in the Power Pivot window and ensure that the data types match for both columns.

Frequently Asked Questions

Do I need to have the tables on the same Excel sheet to create a relationship?

No, you do not. In fact, it is better practice to separate your source data from your Pivot Tables. You can have the tables in completely different tabs or even in different files, as long as you can access both of them from the same workbook or data model.

What happens if I delete the source data?

If you delete the rows of data in the original Excel sheet, the Pivot Table will not update. You must refresh the Pivot Table to pull data from the source again. If you delete the entire table, you will need to recreate the relationship in the Data Model.

Can I have more than one relationship between the same two tables?

No, you cannot have more than one relationship between two specific tables in a single data model. If you need to relate them in different ways, you must create separate tables that have been summarized or filtered to support the different relationship requirements.

Why are my totals not adding up correctly?

This usually happens because of incorrect relationship cardinality or incorrect data types. If you have a 'One-to-One' relationship when you should have a 'One-to-Many', the Pivot Table will try to sum the same data multiple times. Check the cardinality and data types to resolve this.

Is it possible to create relationships in the standard Excel Pivot Table feature?

Standard Excel Pivot Tables do not have a built-in interface for creating relationships. You must use the Power Pivot add-in, which is included with modern versions of Excel for Windows. The functionality is fully integrated, but it requires this separate window to manage the data model.