Yes, you can join tables in Power Query using relationships to join data from multiple sources into a single dataset, but you must create a cardinality relationship in the Query Settings pane to enable joins. Before you begin, ensure your tables share a common column with matching data types, such as an ID or Product Code. This guide walks you through creating these connections to merge your data seamlessly.

What You'll Need

  • A data source supported by Power Query: This includes Excel workbooks, CSV files, SQL databases, SharePoint lists, and web sources.
  • Two or more tables with a common key: The tables must contain a column that can be used to match records, often an ID or unique identifier.
  • Power Query Editor: This is built into Excel, Power BI Desktop, and Power Automate. You access it via the "Get Data" or "Transform Data" options in your application.

Step-by-Step

  1. Open the Power Query Editor. In Excel, go to the Data tab and click "Get Data" > "From Table/Range" (if you already have a table selected) or "From File" > "From Workbook" to load your data. In Power BI Desktop, open your report and click "Transform Data" in the Home ribbon.
  2. Load your source data. If you haven't already, load your data into the Power Query Editor. This can be done by selecting a table in your workbook and clicking "Transform Data,” or by navigating to the "Get Data" section and selecting your source type (e.g., Excel Workbook, SQL Database, Web).
  3. Locate the Table Diagram view. In the top-left corner of the Power Query Editor, look for the "Table Diagram” button. Clicking this toggles the view from a list of queries to a visual representation of your tables and their connections.
  4. Drag tables to the canvas. In Table Diagram view, you will see a blank canvas. Find your queries (tables) in the left-hand pane. Drag and drop the tables you want to relate onto the canvas. Arrange them so that the table containing the matching key (the lookup table) is on the left or top, and the table you want to join to it is on the right or bottom.
  5. Connect the tables with a line. Hover your mouse over the column in the lookup table that contains the unique identifier (e.g., "CustomerID"). Click and hold the mouse button, then drag a line to the matching column in the target table (e.g., "CustomerID"). A solid line will appear, indicating a relationship has been created.
  6. Verify the relationship. Once the line is drawn, the relationship is active. If the columns have matching data types (e.g., both are Whole Number), Power Query will automatically set the cardinality to "One-to-One" or "One-to-Many." If the data types do not match, you will need to change the data type of one or both columns in the Applied Steps pane before the relationship can be established.
  7. Apply the changes. Click the "Close & Apply" button in the Home ribbon. Power Query will load the data with the relationships applied. You can now use these relationships to create calculated columns, merge queries, or group data based on the linked tables.

Common Mistakes

One of the most frequent errors when establishing Power Query relationships is ignoring data types. If the key column in one table is formatted as a Text string (e.g., "00123") and the corresponding column in another is a Whole Number (e.g., 123), Power Query cannot match them, even if the values look identical. Always check the data type of your key columns in the Applied Steps pane and convert them to the same format if necessary.

Another common mistake involves creating relationships that are not actually needed for your data model. In Power BI and Excel, too many relationships can slow down your report and create ambiguity in how data is calculated. Only create a relationship if you are actively using it to join tables, filter one table based on another, or merge them into a single result set.

Tips

When working with relationships, it is helpful to use the "Data Types" feature to ensure consistency. Select a column and use the dropdown arrow in the ribbon to explicitly set it to Whole Number, Text, or Date. This prevents silent errors where two columns look the same but are treated differently by the engine.

Always verify that your lookup table has unique values in the key column. If you are relating a "Customer" table to an "Orders" table, the "CustomerID" column in the Customer table should have no duplicates. Duplicate keys in the lookup table will result in multiple matches when Power Query tries to join the tables, which can lead to unexpected results or a massive expansion of your data.

Troubleshooting

If you cannot draw a line between two tables in Table Diagram view, check if the tables have already been merged. A merged query combines two tables into a single table and creates a permanent column that is no longer available for relationship creation. If you see a merged query, you must undo the merge or create a new query that references the original tables individually.

If you see a red zigzag line instead of a solid line, it indicates a cardinality error. This usually means the data types of the two columns do not match. Go to the Applied Steps pane for the table, find the step where the column was created or transformed, and change the data type of the column to match the other table. Once the types match, the red line should turn solid.

Frequently Asked Questions

Can I create relationships between tables in Excel Online?

No, the ability to create relationships between tables is not available in Excel Online. You must use the full desktop version of Excel or Power BI Desktop to create and manage relationships.

What is the difference between a relationship and a merge query?

A relationship is a logical connection between tables that allows for filtering and data modeling. A merge query is an action that physically combines two tables into a single table, creating new columns that contain data from both source tables.

Why does my data count increase when I add a relationship?

This happens when you create a one-to-many relationship. For every row in the "one” table, Power Query will create a row for every matching row in the "many” table. This expansion is necessary to show all data points in your report.

Can I change the direction of a relationship?

Yes, you can change the direction of a relationship, but you cannot change the cardinality (one-to-one or one-to-many) once it is created. To change the direction, go to the "Manage Relationships” dialog box in the Home ribbon, select the relationship, and choose a different direction (Single, Both, or Many).