Power Query Merge Tables: Step-by-Step Guide
In this article
Power Query merge tables combines data from two or more tables based on matching columns, letting you enrich your dataset with related information—like adding customer names to sales records or linking inventory levels to product IDs. This is essential for clean, actionable analysis in Excel or Power BI. Before you begin, ensure both tables are loaded into Power Query and share at least one common column with consistent data types (e.g., both are text or both are numbers).
What You'll Need
- Microsoft Excel 2016 or later, or Power BI Desktop
- Two or more tables loaded into Power Query (from Excel sheets, CSV, databases, etc.)
- A common column between tables (e.g., ProductID, CustomerID, Date)
- Clear understanding of which table is your primary (left) and which is the lookup (right)
Step-by-Step
- Open the Power Query Editor by selecting any cell in your main table, then going to the Data tab > Get & Transform > Transform Data (in Excel) or selecting Transform Data in Power BI.
- In the Power Query Editor, locate the table you want to merge into (the primary table). This is the one you want to add new columns to—e.g., your Sales table.
- Click on the Home tab in the ribbon, then select Merge Queries > Merge Queries as New. (Do not use Merge Queries if you want to keep the original table unchanged.)
- In the Merge dialog box, under Table1, select your primary table. Under Table2, select the lookup table you want to pull data from—e.g., your Customers table.
- In the Column fields, choose the matching column from Table1 (e.g., CustomerID from Sales) and the matching column from Table2 (e.g., CustomerID from Customers). The selected columns must have the same data type; if one is text and the other is number, convert one using the Change Type option under the Transform tab.
- Under Join Kind, select Left Outer (keep all rows from Table1) if you want to preserve every row from your primary table even if there’s no match. Choose Inner Join if you only want rows where a match exists in both tables. Avoid Full Outer unless you specifically need unmatched rows from both sides.
- Click OK. Power Query will add a new column titled with the name of the lookup table (e.g., "Customers") containing a Table icon.
- Click the expand icon (two arrows) in the header of the newly added column. A dialog will appear listing all columns from the lookup table.
- Select the specific columns you want to bring into your primary table—e.g., CustomerName, City, Email. Deselect any you don’t need to reduce clutter and improve performance.
- Ensure "Use original column name as prefix" is unchecked unless you want to distinguish merged columns (e.g., Customers.CustomerName). Click OK.
- Review your merged table. New columns from the lookup table should now appear alongside your original data.
- Click Close & Load to return the merged table to Excel or Power BI. If you need to refresh later, right-click the query in the Queries & Connections pane and select Refresh.
Common Mistakes
- Mismatched data types—e.g., merging a text ID column with a number ID column. Always check the data type icon (ABC or 123) in the column header and convert using Transform > Data Type.
- Using the wrong Join Kind—Left Outer is safest for beginners. Inner Join hides unmatched rows, which can mislead analysis if you assume all records should have matches.
- Forgetting to expand columns after merging. The merged table appears unchanged until you click the expand icon; many users think the merge failed.
- Merging on columns with leading/trailing spaces or inconsistent capitalization. Use the Trim function (Transform > Trim) and ensure consistent formatting before merging.
- Trying to merge on multiple columns without selecting them all in the Merge dialog. Power Query requires you to select each matching column pair individually; you can’t merge on a composite key unless you select all components.
Tips
- Always duplicate your original query before merging (right-click > Duplicate) so you can revert if something goes wrong.
- Use named queries (right-click query > Rename) like "Sales" and "CustomerDetails"—this makes merging easier to follow and reduces confusion.
- For large datasets, use Inner Join to reduce memory usage and improve refresh speed.
- If merging with a table from a database, ensure the connection is stable. Power Query may fail if the source is offline during refresh.
- Use the Advanced Editor to review the M code if you’re troubleshooting. Look for the Table.NestedJoin function to confirm the join logic.
- After merging, sort your data by the merged column to visually verify matches—this helps spot nulls or duplicates quickly.
Troubleshooting
- No new columns appear after merge: You likely forgot to click the expand icon. Find the merged column with the table icon and click the double arrows.
- Empty or null values in merged columns: Check if the lookup table has matching values. Use Filter on the key column in the lookup table to see if the ID exists. Also verify data types match.
- Power Query freezes during merge: Close and reopen Excel or Power BI. If the tables are very large (over 100k rows), consider filtering them down before merging—use Remove Rows > Remove Top/Bottom or Filter to keep only relevant data.
- "Cannot convert value ... to type Text" error: One of your key columns contains mixed data types. Go to the Transform tab, select the column, and choose Change Type > Text (or Number). Then retry the merge.
- Duplicate rows after merging: This happens if the lookup table has multiple rows with the same key value (e.g., two addresses per customer). Use Remove Duplicates on the lookup table’s key column before merging, or use Group By to aggregate values.
- Refresh fails with "The operation cannot be completed" error: Ensure the source files or databases are accessible. If using Excel files, confirm they haven’t been moved or renamed. Reconnect the source under Data > Queries & Connections > Right-click query > Properties > Connection.