The Table.ExpandTableColumn function takes a column where every cell holds a small table and opens those tables up into regular rows and columns. It’s the step Power Query writes for you when you click the expand icon after a merge or a Group By.
Writing it yourself lets you set the exact names of the new columns in the same step, and even build the column list with a formula.
In this article, I’ll show you how it works with merges, grouped data, several Excel tables, and lists of records.
Follow along with the example file
Table.ExpandTableColumn Function Examples.xlsx
Table.ExpandTableColumn Function Syntax
Table.ExpandTableColumn(table as table, column as text, columnNames as list, optional newColumnNames as nullable list) as table
- table – the table that has the column you want to expand.
- column – the name of the column that holds the nested tables, in double quotes (for example “Customer Details”).
- columnNames – a list of the columns you want to pull out of the nested tables, such as {“Customer Name”,”City”}. Any column you leave out of this list is not expanded.
- newColumnNames (optional) – a list of new names for the expanded columns, in the same order as columnNames. Use it to rename the columns or to avoid a clash with a column that already exists in the table.
What it returns – a table where the nested column is replaced by the columns you picked. If a nested table has more than one row, the outer row is repeated once for each of those rows.
Besides nested tables, the function can also expand a column that holds lists of records (more on this in Example 9).
When to Use the Table.ExpandTableColumn Function
Use this function when you need to:
- Bring matching columns from a second table after merging two queries (the Power Query version of a lookup)
- Rename the columns you bring in, so they don’t clash with columns you already have
- Turn one row into several rows when a match returns more than one record
- Add a group total (or any other group-level value) to every row of the original data
- Expand every column of a lookup table without typing the column names
- Stack several Excel tables from the same workbook into one table
- Flatten lists of records, like the ones you get from JSON data
The example file has one sheet for each source table, and each example is saved as its own query. To see the M code, go to Data > Queries & Connections and double-click the query.
Example 1: Bring In Columns From a Merged Table
Let’s start with the most common reason you’ll use this function, which is getting columns from another table after a merge.
Below I have an Orders table (with Order ID, Customer ID, and Amount) and a Customers table (with Customer ID, Customer Name, and City), and I want to show the customer’s name and city next to each order.
I’ve merged the two tables on Customer ID, so each order now has a Customer Details column with the matching customer’s row tucked inside it.

Each cell in the Customer Details column shows the word Table, because it holds a whole table and not a single value.
Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ExpandTableColumn(Merged,"Customer Details",{"Customer Name","City"})
Result: The Customer Details column is replaced by a Customer Name column (Caleb Mason, Allison Wallace, Gabriel Smith, Caleb Mason, Nancy King) and a City column (Denver, Seattle, Austin, Denver, Boston).

Here, Merged is the name of the previous step, “Customer Details” is the column that holds the nested tables, and {“Customer Name”,”City”} is the list of columns I want to take out of them.
I didn’t list Customer ID because the Orders table already has it.
Here is the complete query, so you can see where the Merged step and the Customers step come from:
let
Source = Excel.CurrentWorkbook(){[Name="Orders"]}[Content],
Customers = Excel.CurrentWorkbook(){[Name="Customers"]}[Content],
Merged = Table.Buffer(Table.NestedJoin(Source,{"Customer ID"},Customers,{"Customer ID"},"Customer Details",JoinKind.LeftOuter)),
Expanded = Table.ExpandTableColumn(Merged,"Customer Details",{"Customer Name","City"})
in
Expanded
The Customers step reads the Customers table from the workbook, and the Merged step uses the Table.NestedJoin function to match the two tables on Customer ID. I’ve left out the Changed Type step in all the examples to keep the M code short.
Important: Power Query can reorder rows after a merge and expand. Table.Buffer around the merge kept the order here but isn’t guaranteed, so if order matters, add an Index column to the first table before the merge and sort on it after the expand.
The same Table.Buffer wrapper is used in all the merge examples below.
Example 2: Rename the Columns While Expanding
When you expand columns, they keep the names they had in the nested table. Quite often those names don’t work well in the final table.
Below I have a SalesLines table (with Line, SKU, and Qty) and a Products table (with SKU, Product, and Price), and I want to bring in the product name and price as Product Name and Unit Price.
I’ve merged the two tables on SKU into a Product Details column, the same way as in Example 1.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ExpandTableColumn(Merged,"Product Details",{"Product","Price"},{"Product Name","Unit Price"})
Result: Two new columns, Product Name (Office Chair, Monitor Stand, Desk Lamp, Office Chair) and Unit Price (149, 42, 35, 149).

In the above formula, the fourth argument gives the new names, in the same order as the third argument. So Product becomes Product Name and Price becomes Unit Price, and you don’t need a separate Table.RenameColumns step.
If you use the expand icon instead, the “Use original column name as prefix” option is checked by default.
The icon then fills in newColumnNames for you with names like Product Details.Product, so you’d need another step to rename them to Product Name and Unit Price.
Example 3: Fix the “Field Already Exists” Error
This next one comes up when both tables have a column with the same name.
Below I have a Tasks table (with Task, Owner ID, and Status) and an Owners table (with Owner ID, Owner, and Status), and I want to bring in the owner’s name and their status.
I’ve merged the two tables on Owner ID into an Owner Details column.

Both tables have a Status column. In Tasks it’s the task status (Done, In Progress, or Not Started), and in Owners it’s whether the person is Active or On Leave.
If you expand Status with its original name, Power Query stops with the error “Expression.Error: The field ‘Status’ already exists in the record.” That’s because the table already has a Status column.
To fix it, add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ExpandTableColumn(Merged,"Owner Details",{"Owner","Status"},{"Owner","Owner Status"})
Result: Two new columns, Owner (Carl Clark, Dorothy Stewart, Heather Wright, Carl Clark) and Owner Status (Active, On Leave, Active, Active), while the original Status column stays as it was.

Here, the new names list keeps Owner as it is and renames the nested Status to Owner Status. Every name in the newColumnNames list has to be different from the columns already in the table.
Example 4: Get One Row for Each Match
This next one shows what happens when a row has more than one match.
Below I have a Projects table (with Project and Client) and an Assignments table (with Project, Team Member, and Hours), and I want to list every team member next to their project.
I’ve merged the two tables on Project into a Team column, and some projects have more than one team member.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ExpandTableColumn(Merged,"Team",{"Team Member","Hours"})
Result: 5 rows instead of 3. Website Refresh appears twice (Evan Bennett and Paige Miller), Payroll Audit once (Blake Webb), and Data Migration twice (Zoe Davis and Samantha Evans).

When a nested table has more than one row, Table.ExpandTableColumn repeats the outer row once for each of them. So the Client column is copied down to every team member of that project.
That’s what you want when you need one row per match. If you expected only one match per row, a sudden jump in row count usually means the lookup table has duplicate keys.
Example 5: Rows That Don’t Have a Match
Now let’s see what happens when a row doesn’t find anything in the other table.
Below I have a Shipments table (with Shipment, Zone Code, and Weight (kg)) and a Zones table (with Zone Code, Zone, and Carrier), and I want to add the zone name and carrier to each shipment.
One shipment, SH-503, has the zone code X, which isn’t in the Zones table. I’ve merged the two tables on Zone Code into a Zone Details column.

For SH-503, the nested table is empty, because no zone has the code X.
Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ExpandTableColumn(Merged,"Zone Details",{"Zone","Carrier"})
Result: Zone and Carrier columns with North/FastFreight, West/FastFreight, null/null, and South/RoadLink.

The merge here is a left outer join, so SH-503 stays in the table even though it has no match. Expanding an empty nested table gives you null in each new column for that row.
If you’d rather drop the rows that don’t match, change JoinKind.LeftOuter to JoinKind.Inner in the merge step. If you want to keep them, you can replace the nulls with something like “Unknown” in the next step.
Follow along with the example file
Table.ExpandTableColumn Function Examples.xlsx
Example 6: Add a Group Total to Every Row
This one uses the function with the Table.Group function instead of a merge.
Below I have a RepSales table with each sales rep’s Region and Sales, and I want each row to also show the total sales of its region.
I’ve grouped the data by Region with two aggregations, a Region Total (the sum of Sales) and a Details column that keeps all the original rows of each region.

Here is the Group By step that creates the Grouped table:
= Table.Group(Source,{"Region"},{{"Region Total",each List.Sum([Sales]),type number},{"Details",each _,type table}})
The each _ part is what the All Rows option in the Group By dialog box writes, and it stores every row of the group as a nested table.
Now add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ExpandTableColumn(Grouped,"Details",{"Rep","Sales"})
Result: All 6 reps are back, and each row shows its region’s total. The East rows show 10700, and the West rows show 11600.

In the above example, the Group By step collapses the six rows into two rows (East and West), and Table.ExpandTableColumn opens them back up.
Each rep’s row now has the region total next to it, so you can add a percentage of region column in the next step.
Note that the rows now come out grouped by region (all the East reps first, then the West reps), not in the original order.
Example 7: Expand All Columns Without Typing Their Names
The formula the expand icon writes has every column name typed in, so if the lookup table gets a new column later, your query won’t pick it up.
Below I have a Staff table with employee names and a StaffInfo table (with Emp ID, Department, Location, and Start Year), and I want to bring in every StaffInfo column except Emp ID. I’ve merged the two tables on Emp ID into a Details column.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ExpandTableColumn(Merged,"Details",List.RemoveItems(Table.ColumnNames(StaffInfo),{"Emp ID"}))
Result: Three new columns, Department, Location, and Start Year, filled in for all four employees.

Here, StaffInfo is the step that reads the StaffInfo table. Table.ColumnNames(StaffInfo) returns all four of its column names, and List.RemoveItems takes Emp ID out of that list, since the Staff table already has it.
So if someone adds a Manager column to the StaffInfo table, the next refresh expands it too, with no change to the query.
Just make sure the new column doesn’t have the same name as a column in Staff, or you’ll get the “already exists” error from Example 3.
Example 8: Combine Several Excel Tables Into One
Table.ExpandTableColumn is also a quick way to stack tables that live in the same workbook.
Below I have three Excel tables, Sales_Austin, Sales_Denver, and Sales_Miami, each with a Product and a Units column, and I want them in one table with the store name on every row.
Excel.CurrentWorkbook() lists every table in the workbook, with each table’s data in a Content column and its name in a Name column.
I’ve filtered this list down to the three Sales_ tables and sorted them by name, so the Sorted step has one row per store.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ExpandTableColumn(Sorted,"Content",{"Product","Units"})
Result: One table with 6 rows. Each store has a Laptop row and a Tablet row, and the Name column shows Sales_Austin, Sales_Denver, or Sales_Miami.

The expanded columns take the place of the Content column, which was the first column, so Product and Units come first and Name ends up last.
Here is the complete query:
let
Source = Excel.CurrentWorkbook(),
Filtered = Table.SelectRows(Source,each Text.StartsWith([Name],"Sales_")),
Sorted = Table.Sort(Filtered,{{"Name",Order.Ascending}}),
Expanded = Table.ExpandTableColumn(Sorted,"Content",{"Product","Units"})
in
Expanded
The Filtered step keeps only the tables whose names start with Sales_, so the other tables in the file (and the query’s own output, if you load it to a sheet) are left out.
Any new table you add with a name that starts with Sales_ is picked up on the next refresh.
The Sorted step uses Table.Sort to put the stores in A to Z order, because Excel.CurrentWorkbook() doesn’t promise any particular order.
Example 9: Expand a Column of Record Lists
Data that comes from JSON or a web API often has a column where each cell is a list of records, not a table. Table.ExpandTableColumn can expand these too.
Suppose you have three orders, and each order has an Items column with a list of the items in it (the item name and the quantity).
Create a new blank query (Home > New Source > Blank Query), open the Advanced Editor, and use this query:
let
Source = Table.FromRecords({[Order="A-101",Items={[Item="Pen",Qty=3],[Item="Notebook",Qty=2]}],[Order="A-102",Items={[Item="Stapler",Qty=1]}],[Order="A-103",Items={[Item="Marker",Qty=4],[Item="Folder",Qty=5]}]}),
Expanded = Table.ExpandTableColumn(Source,"Items",{"Item","Qty"})
in
Expanded
Result: 5 rows, one for each item. A-101 has Pen (3) and Notebook (2), A-102 has Stapler (1), and A-103 has Marker (4) and Folder (5).

Here, the Source step builds the orders table with the Items lists in it, and Table.ExpandTableColumn turns each record into its own row in one step.
If you use the expand icon on a list column instead, Power Query does this in two steps, Expand to New Rows (Table.ExpandListColumn) and then expanding the records (Table.ExpandRecordColumn).
Other Excel Articles You May Also Like:
- Json.Document Function in Power Query M
- Table.FromList
- Excel.Workbook
- Table.ExpandRecordColumn function
- Table.Join – Use Table.Join in Power Query M to join two tables.
- Table.ColumnNames – Use Table.ColumnNames in Power Query M to list a table’s column names.
- Table.Combine – Use Table.Combine in Power Query M to stack multiple tables into one by appending rows.
- List.Combine – Use List.Combine in Power Query M to join lists into one.