A nested join in Power Query (also called a table join) combines two tables by matching rows on a key column, but instead of flattening the result, it returns a new column containing a whole table in each row. You then expand the columns you need. This is useful when you want to bring in related records without duplicating the main table's rows, or when you need to filter the joined table before expanding. To do it, you need two queries loaded in Power Query, a common key column in each, and the Merge Queries command. The steps below work in Excel and Power BI Desktop; menu labels can differ slightly by version or region.
What You'll Need
- Two tables loaded into Power Query (as queries, not just worksheets).
- A key column in each table that contains matching values. The data types should match (both text or both number).
- Basic familiarity with the Power Query Editor: the Home tab, the Queries pane, and the Applied Steps list.
Step-by-Step
- Load both tables into Power Query. In Excel, select your first table and go to Data > From Table/Range. Repeat for the second table. In Power BI Desktop, use Home > Transform data to open the Editor, then Home > New Source for each table. Each table appears as a separate query in the Queries pane on the left.
- Clean the key columns. Click each key column and confirm the data type is correct (for example, Text or Whole Number). Trim spaces if needed: right-click the column header > Transform > Trim. Matching is case-sensitive by default in some connectors, so standardize case if your data varies.
- Start the merge from the table you want to keep as the base. Select the main query in the Queries pane. On the Home tab, click Merge Queries (or Merge Queries as New if you want a separate query). The Merge dialog opens.
- Choose the second table and the matching columns. In the top dropdown, pick the second query. Click the key column in the top preview, then click the matching key column in the bottom preview. Power Query highlights both. If the column names differ, that is fine; the match is based on the columns you click, not the names.
- Select the join kind. The default is Left Outer, which keeps all rows from the first table and adds matches from the second. Other options include Inner (only matching rows), Full Outer (all rows from both), Left Anti (rows in the first with no match), and Right Anti. For a nested join, Left Outer is the most common starting point.
- Click OK. A new column appears with a table icon in each row. This is the nested table. The column is usually named after the second query. Do not expand it yet if you want to filter first.
- Expand the columns you need. Click the expand icon (two arrows) in the new column header. In the menu, clear the checkbox for the key column if you do not want it duplicated, then select the columns to bring in. Click OK. The nested tables become flat columns, and the rows expand accordingly.
- Rename and reorder as needed. Double-click the new column headers to rename them. Drag columns to reorder. Check the Applied Steps list to confirm each action is recorded; you can click any step to review or delete it.
- Load the result. In Excel, go to Home > Close & Load > Close & Load To to choose a worksheet or data model. In Power BI, use Home > Close & Apply to apply changes.
Common Mistakes
- Mismatched data types. If one key column is text and the other is number, the merge returns no matches. Convert both to the same type before merging.
- Hidden spaces or case differences. Trailing spaces or inconsistent capitalization cause missed matches. Trim and standardize case on both key columns.
- Expanding too early. If you expand immediately, you lose the ability to filter the nested table first. Filter the nested column (using the table icon) before expanding when you only need a subset.
- Duplicate keys causing row multiplication. If the second table has multiple rows per key, expanding will multiply rows in the result. Check for duplicates or aggregate the second table first.
- Forgetting to set the join kind. Leaving the default Left Outer when you need Inner can bring in nulls you did not expect. Review the join kind in the Merge dialog.
Tips
- Use Merge Queries as New to keep the original queries intact and create a separate merged query.
- Rename the nested column right away to something meaningful; the default name can be confusing later.
- Before expanding, click the table icon in a cell to preview the nested table and confirm the match looks correct.
- If you need only a count or a single value from the second table, consider aggregating the second table before merging to avoid row multiplication.
- Keep the Applied Steps list clean; delete unnecessary steps to make the query easier to maintain.
Troubleshooting
If the merge returns a column of nulls or empty tables, check the key columns for data type mismatches, leading or trailing spaces, and case differences. Use Trim and Transform > Lowercase on both columns. If the row count increases unexpectedly after expanding, the second table likely has duplicate keys; remove duplicates or aggregate before merging. If the expand icon does not show the columns you expect, the nested table may be empty for those rows, or the column names may have changed; refresh the preview. If the query is slow, reduce the number of columns in the nested table before merging, or filter the source tables earlier. If you accidentally expand the wrong columns, delete the expand step in the Applied Steps list and redo it.
Frequently Asked Questions
What is a nested join in Power Query?
A nested join merges two tables and returns a column containing a table in each row, rather than flattening the result immediately. You can then expand selected columns.
How do I expand only some columns from the nested table?
Click the expand icon in the nested column header, clear the checkbox for the key column, and select only the columns you want. Click OK.
Why does my merge return no matches?
Common causes are mismatched data types, extra spaces, or case differences in the key columns. Standardize both key columns before merging.
Can I merge more than two tables?
Yes. Merge two tables first, then merge the result with a third table using the same steps. Each merge adds a new nested column.
What is the difference between Left Outer and Inner join?
Left Outer keeps all rows from the first table and adds matches from the second; unmatched rows get nulls. Inner keeps only rows with matches in both tables.
Does the order of tables in the merge matter?
Yes. The first table is the base; the join kind determines which rows are kept. Swap the tables if you need a different base.