Power Query Table.ExpandTableColumn: How to Use It
In this article
Table.ExpandTableColumn takes a column that holds nested tables and turns each nested table into new columns in the outer table. You need a query with a column of type Table, and you need to know the names of the columns inside those nested tables. The function is available in Power Query for Excel, Power BI, and other Microsoft products that use Power Query (labels can differ slightly by version or product).
What You'll Need
- A Power Query query that already contains a column of nested tables. This often comes from combining files, expanding a JSON or XML record, or using a function that returns a table per row.
- The exact names of the columns inside the nested tables that you want to bring out. You can see these by clicking the expand icon in the column header and reading the list, or by opening the Power Query Editor and inspecting a cell.
- Basic familiarity with the Power Query Editor and the formula bar. The function is usually applied through the user interface, but knowing how to read the generated M code helps when you need to adjust it.
Step-by-Step
- Open your query in the Power Query Editor. In Excel, go to Data > Get Data > Launch Power Query Editor (or open an existing query). In Power BI Desktop, use Home > Transform data. The exact menu labels can vary slightly by version and product.
- Locate the column that contains nested tables. Its header usually shows a small table icon and the word “Table” in each cell, not the actual data. If the column type is not Table, the expand option may not appear; you can set the type by clicking the type icon in the column header and choosing Table.
- Click the expand icon (two small arrows pointing outward) on the right side of the column header. A menu opens showing the columns found inside the nested tables.
- Choose “Expand” rather than “Aggregate” if you want the actual values. The menu lists the available nested columns with checkboxes.
- Select only the columns you need. Expanding every column can make the query wide and slow, and it can create duplicate column names. If you are unsure, expand one or two columns first, check the result, and then expand more.
- Decide whether to keep the original column. The option “Use original column name as prefix” adds the outer column name to each new column (for example, “Sales.Amount”). This helps avoid name clashes when several nested columns share a name. Clear the checkbox if you want clean column names and you know there are no conflicts.
- Click OK. Power Query adds the selected nested columns to the outer table and fills each row with the corresponding values. Rows where the nested table was null or empty will show null in the new columns.
- Review the result. Check that the new columns have the expected data types. If a column comes in as Any or Text when it should be a number or date, click the type icon in the header and set the correct type.
- If you need to adjust the expansion later, you can edit the step in the Applied Steps pane. Select the step named something like “Expanded TableColumn” and use the gear icon to reopen the dialog, or edit the M code directly in the formula bar.
The function itself looks like this in M code: Table.ExpandTableColumn(table, columnName, columnNames, newColumnNames). The first argument is the outer table, the second is the name of the column containing nested tables, the third is a list of nested column names to expand, and the optional fourth argument lets you rename the resulting columns. For example, Table.ExpandTableColumn(Source, "Details", {"Name", "Amount"}, {"CustomerName", "Total"}) pulls two nested columns out and renames them in one step. If you omit the fourth argument, the original nested column names are used.
Common Mistakes
- Expanding the wrong column. The expand icon appears only on columns of type Table. If you click the icon on a record column, you get a different dialog. Check the column type first.
- Selecting all nested columns by habit. This often creates duplicate column names, bloats the query, and makes later steps harder to read. Expand only what you need.
- Ignoring null nested tables. If some rows have no nested table, the new columns will contain null for those rows. That is normal, but it can break calculations later if you do not handle nulls.
- Forgetting to set data types. Expanded columns sometimes arrive as Any. Set the correct type so sorting, filtering, and relationships work as expected.
- Renaming columns after expansion instead of during it. If two nested tables have columns with the same name, use the prefix option or the rename argument in the function to avoid ambiguity.
Tips
- Use the formula bar to inspect the generated step. Seeing the M code helps you understand what the dialog did and makes it easier to modify.
- If you expand many columns, consider expanding in stages and checking row counts after each stage. A sudden jump in rows usually means a nested table had multiple rows.
- When the nested column names vary between rows, expansion can produce nulls for columns that do not exist in some nested tables. That is expected behavior.
- If you need to keep the original nested table column for reference, expand a copy instead of the original, or use the prefix option so you can tell the columns apart.
- For repeated patterns, consider creating a custom function that expands the nested table consistently, then invoke it on each row.
Troubleshooting
If the expand icon does not appear, the column is probably not typed as Table. Click the type icon in the column header and choose Table. If the icon appears but the menu is empty, the nested tables may have no columns or may be empty; check a cell by clicking it and looking at the preview below the ribbon.
If you get an error such as “The column 'X' of the table wasn't found,” the nested column name you specified does not exist in at least one nested table. Open the expand dialog and confirm the exact spelling, including spaces and capitalization. If some nested tables have different column sets, expansion still works but fills missing values with null.
If the query becomes very slow after expansion, you may have expanded a column with many nested columns or many rows. Try expanding fewer columns, filtering the outer table first, or removing unnecessary steps. Also check that the data source supports query folding; expansion itself often prevents folding, so consider doing heavy filtering before expanding.
If new columns have unexpected names, review the “Use original column name as prefix” setting and any rename argument in the M code. Duplicate names are automatically suffixed by Power Query, which can be confusing; renaming explicitly is clearer.
Frequently Asked Questions
What does Table.ExpandTableColumn do?
It takes a column containing nested tables and adds the columns from those nested tables to the outer table, one row per original row.
Can I expand only some columns from the nested table?
Yes. In the expand dialog, select only the columns you want. In M code, pass a list containing just those column names as the third argument.
Why do I get nulls after expanding?
Nulls appear when a nested table is empty or missing, or when a selected nested column does not exist in some nested tables. That is normal and can be filtered or replaced later.
How do I rename the expanded columns?
Use the optional fourth argument in the function with a list of new names, or rename the columns in a separate step after expansion.
Does expanding a table column affect query folding?
Expansion typically breaks query folding because it is a shaping operation. Filter and reduce data before expanding when possible.
Can I undo an expansion?
Yes. Delete the expansion step in the Applied Steps pane, or edit it to change which columns are expanded. The original nested column remains unless you removed it.