If your pivot tables show disconnected data—sales numbers missing customer names or inventory gaps where orders don’t match shipments—you’re missing the point of pivot analysis. The solution: establish relationships between tables so pivot tables automatically pull related records. This isn’t just about surfacing values; it’s about ensuring your dashboards reflect real-world dependencies like orders tied to customers or products linked to suppliers. Without proper linking, every filter or summary will introduce artificial gaps. Here’s how to do it right across Excel, Power Query, and modern tools.
What You'll Need
- Two or more datasets in your source tool (Excel, Power BI, Google Sheets)—one with primary keys (identifiers like IDs), the other with fields referencing those keys (foreign keys).
- Access to the tool’s data modeler or import/merge interface (Excel’s Power Query or Power BI’s data view).
- Desired pivot table layout—you’ll modify it to reflect the relationship after linking.
- A test dataset with at least 50 records per table to demonstrate the relationship works (50 is the minimum to catch edge cases).
Step-by-Step
- Prepare Your Data
In both tables, identify the key columns:
- Primary table: A unique identifier (e.g., `CustomerID` in the Customers table). It must be numeric or a consistent string like "ABC123".
- Related table: A column matching that identifier (e.g., `CustomerID` in the Orders table). This is the foreign key.
Validate the keys:
- Check for nulls or duplicates in the primary key column. Clean them using Excel’s
UNIQUEfunction or Power Query’s "Remove Rows" > "Rows with Null Values". - Ensure the foreign key column has the same data type (numeric = numeric, text = text; mixed types break links). Use Power Query’s "Transform" > "Convert to Columns" if needed.
- Choose Your Tool
For Excel 2016+:
- Open your workbook, go to
Data>Get Data>From Other Sources>From Database(for SQL) orFrom Table/Range(for flat files). - Import both tables into separate datasets. This creates linked queries in Power Query (the "Data Model" view).
For Power BI Desktop:
- Drag the primary table into the model view. Right-click its icon to "Add Relationship".
- Select the related table’s foreign key column, then click the primary key column to create a one-way relationship.
For Google Sheets:
- Use the
IMPORTRANGEfunction to link datasets, but note: relationships aren’t native—you’ll manually match rows using FILTER() or QUERY().
- Open your workbook, go to
- Define the Relationship
In Power Query (Excel) or Power BI:
- Create a relationship between the primary and foreign key columns. In Excel’s Data Model, drag the cursor between the two columns to snap them together.
- Set cardinality:
- One-to-many: Primary key in one table, multiple records in the related table (e.g., one customer = many orders).
- One-to-one: Primary key = single related record (e.g., one supplier = one warehouse).
- Many-to-one: Rare; use this only if you’re tracking reverse dependencies like "which products use a single inventory item".
- Configure options:
- Filter rule: "Only include rows that are related" (default).
- Filter on nulls: "Include rows where the related key is null" if you want to allow non-matched records.
- Filter direction: "Left or Right" determines which table’s records appear when filtering (left = primary table’s view).
- Build the Pivot Table
For Excel:
- Insert a pivot table from the Data Model (not your source data). Drag the primary key to Rows and the related field to Values.
- Add a filter to the secondary table’s foreign key to see only related records. The pivot table will now auto-expand to include all matching data.
For Power BI:
- Create a pivot table in the "Report" view. Drag the primary key to "Rows" and the related field to "Values".
- Use the "Filter" feature to isolate the related table’s column. The pivot will automatically join data.
- Verify the Link
Test the relationship by:
- Filtering the pivot table on the primary key. All related records from the secondary table should appear.
- Adding a second filter on the secondary table’s column. The pivot should only show matching records.
- Checking for "orphaned" rows: if a record in the primary table has no matches in the secondary table, it will show as "null" in the pivot.
Common Mistakes
- Misaligned Keys
Foreign keys don’t match the primary key’s format (e.g., a numeric ID vs. a text string like "CUST-001"). Solution: Standardize formats in Power Query’s "Transform" tab or use a function like
TEXTBEFORE/TEXTAFTERto clean names. - Ignoring Nulls
Relationships default to excluding nulls, which hides records where the related field is empty. Force them into the pivot by setting the "Filter on nulls" option to "Include rows where the related key is null".
- Cardinality Errors
Creating a many-to-one relationship between a table with 10,000 rows and one with 200 can cause performance issues. Limit to practical cardinalities (e.g., customers to orders: 1-to-many is fine; orders to customers: 1-to-many is also fine).
- Forgetting Data Types
Mixing numeric IDs with text codes (e.g., "ORD-123") will break the relationship. Convert all keys to the same type before linking.
- Not Testing with Real Data
Linking two empty tables doesn’t reveal edge cases like duplicate keys or missing values. Use a dataset with 50+ records to spot issues like:
- Too many nulls in the foreign key.
- Keys that share values (e.g., CustomerID = 1 appears in two tables).
- Performance lag when filtering.
Tips
- Use the Data Model Visualization
In Excel, right-click the Data Model view’s "Relationships" tab to see your links. Drag fields to "Rows" or "Values" in the pivot table from here—it’s more reliable than dragging source data.
- Document Your Relationships
Add comments in the relationship editor (Excel) or model view (Power BI) explaining cardinality and filter directions. This saves time for others (or your future self).
- Performance Optimization
For large datasets:
- Index the primary key column in Power Query’s "Advanced Editor" by adding
Index(Table.ColumnName)to the key field. - Avoid self-referential relationships (e.g., linking a table to its own primary key).
- Use "Defer Loading" in Power BI/Power Query to load data only when needed by the pivot.
- Index the primary key column in Power Query’s "Advanced Editor" by adding
- Backup Your Data
Relationships aren’t saved with your workbook. Export your model as a JSON file in Excel (File > Save As > Workbook Compatibility) or publish your Power BI dataset to share the model.
- Visualize the Relationship
Create a simple line chart in Power BI/Excel showing the cardinality. For example, a line from "Customers" to "Orders" with a "1:10" annotation helps explain your design.
Troubleshooting
- No Data Appears in the Pivot
Check these steps:
- Verify the relationship is "on". In Excel, drag the cursor between columns to snap them together. If it’s "off", click the dropdown arrow to turn it on.
- Ensure both tables are connected to the pivot (Excel) or selected in Power BI’s model view.
- Filter the source tables before creating the pivot—blank tables won’t generate data.
If that did not work: Restart Excel/Power BI. Update to the latest version (relationships often work better with recent updates).
- Infinite Loops or Circular References
You’ve accidentally linked two tables that reference each other directly (e.g., a table’s foreign key is the primary key of another). Solution:
- Right-click the relationship in the Data Model view and select "Delete".
- Recreate the relationship with the correct cardinality.
Warning: This won’t break your data—it’s just a logical error.
- Slow Performance When Filtering
Large datasets with many-to-many relationships (e.g., products × suppliers) will struggle. Solutions:
- Break the relationship into sub-queries (e.g., use a "SupplierID" table with one-to-many links to both Products and Orders).
- In Power BI, use "Background Loading" for related tables.
- Reduce the number of pivot rows/columns.
- Relationship Not Showing in Pivot
This happens if:
- The pivot table is created from source data (not the Data Model). Right-click the pivot and select "Edit" > "PivotTable Parameters" to force it to use the Data Model.
- The relationship is one-way (e.g., Customers → Orders). Add a reverse filter to ensure data flows both directions.
Frequently Asked Questions
What happens if I delete a row in the primary table?
The related rows in the secondary table won’t disappear—only their visibility will change. To remove orphaned records, use Power Query’s "Merge Queries" step to append new data after the deletion. In Excel, refresh the pivot table after cleanup.
Can I use non-primary keys (like email addresses) as foreign keys?
Yes, but only if they’re guaranteed to be unique within their table. Mixing email addresses with other fields (e.g., names + IDs) risks collisions. Always validate uniqueness with Power Query’s "Distinct" function before linking.
My pivot shows blank cells when filtering. Why?
This usually means:
- The foreign key doesn’t match the primary key’s format (e.g., "CUST-123" vs. "123"). Check data types in Power Query’s "Transform" tab.
- The relationship is set to "Only include rows that are related" but the secondary table has nulls where the key is missing.
- The primary key column is hidden in the pivot table’s settings.
How do I undo a relationship in Excel?
Right-click the relationship line in the Data Model view. Select "Delete". Note: this doesn’t affect your source data—it only removes the logical connection.
What’s the limit for how many tables I can link in Excel?
Excel’s Data Model supports a maximum of 512 tables. In practice, use no more than 10–15 for performance. Complex hierarchies (e.g., Customers → Orders → Products) can be nested but should be simplified if they exceed 3 levels.
Can I use this in Google Sheets?
Google Sheets lacks native relationships, but you can simulate them with:
FILTERto show only matching rows.QUERYto create a self-contained dataset with joins.- External data links (via
IMPORTRANGE) with manual row-matching.
Remember: In Google Sheets, every pivot table is an independent calculation. To "link" data, you must explicitly filter or query for related records.