Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Table.ExpandRecordColumn: How to Use It

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Table.ExpandRecordColumn takes a column whose cells hold records and splits it into separate columns, one per field you choose. You give it the table, the name of the record column, the list of field names to pull out, and optionally the new column names. It is the standard way to flatten nested JSON, API responses, or any structure where one column contains a bundle of related values. You do not need to install anything, but you should know where to run it: the Power Query Editor in Excel (Data > Get Data) or in Power BI Desktop (Transform data). The function itself is written in the M formula language, so you will either use the formula bar or the built-in expand button in the column header.

What You'll Need

  • A table already loaded into the Power Query Editor that contains at least one column of type Record (the column header usually shows the word "Record" or a small table icon).
  • Knowledge of the exact field names inside the record. Clicking any cell in the record column shows the available fields in the preview pane at the bottom.
  • Excel with Power Query (Excel 2016 and later, or Microsoft 365) or Power BI Desktop. The menu labels can differ slightly by version, device and region.

Step-by-Step

  1. Load your data into the Power Query Editor. In Excel, go to Data > Get Data > From File (or From Web) and choose your source, then click Transform Data rather than Load so the editor opens.
  2. Find the column that contains records. Look for the header icon: a record column shows a small table or record symbol, and clicking a blank cell in that column displays the field names and values in the preview at the bottom of the window.
  3. Use the quick method first. Click the expand icon (two arrows pointing away from each other) in the right side of the column header, then choose Expand. A dialog lists every field in the record. Tick the fields you want, untick "Use original column name as prefix" if you want clean names, and click OK.
  4. Check the result. Power Query adds one new column per field and keeps the original record column unless you untick it in the dialog. If the original column is still there, right-click its header and choose Remove.
  5. For precise control, use the formula bar instead. Select the step where you want the expansion to happen, then type a formula such as = Table.ExpandRecordColumn(Source, "Customer", {"Name", "City", "Email"}, {"Customer Name", "Customer City", "Customer Email"}) and press Enter. The first argument is the table, the second is the record column name in quotes, the third is a list of field names to extract, and the fourth is the optional list of new column names.
  6. Match the two lists exactly. The order of the field names must correspond to the order of the new names: the first field gets the first new name, the second field the second name, and so on. If you supply fewer new names than fields, the remaining columns keep their original field names.
  7. Set data types. New columns usually arrive as type Any or Text. Click the type icon in each new column header and choose the correct type (Whole Number, Decimal Number, Date, and so on). Doing this now prevents errors later in the query.
  8. Rename and reorder as needed. Double-click a header to rename it, or drag headers to move them. Keep names unique, because duplicate column names cause errors when the query loads.
  9. Apply the changes. Click Close & Load (Excel) or Close & Apply (Power BI) to write the flattened table back to your workbook or model.

Common Mistakes

  • Passing the wrong column name. The second argument must match the record column's header exactly, including spaces and capitalisation. A typo produces an error saying the column was not found.
  • Listing a field that does not exist in every row. If a record is missing a field, Table.ExpandRecordColumn returns null for that cell rather than failing, but a misspelled field name creates an all-null column, which is easy to miss.
  • Forgetting that nested records can sit inside records. If a field is itself a record, expanding the outer level gives you another record column that needs a second expansion step.
  • Supplying new names in a different order from the field list, which silently swaps the values between columns.
  • Leaving the original record column in place and then loading both it and its expanded columns, which duplicates data and can break relationships in a data model.
  • Expanding before filtering. Expanding a large nested table first and filtering afterwards is slower; filter rows first where you can.

Tips

  • Let the dialog write the formula for you the first time, then inspect the generated step in the formula bar. It teaches you the exact syntax faster than reading documentation.
  • Use the fourth argument to name columns in one pass instead of renaming each one afterwards.
  • If you only need one or two fields, expanding just those keeps the table narrow and the query faster.
  • For a column of lists rather than records, use Table.ExpandListColumn instead; the record function will not work on lists.
  • Keep a copy of the pre-expansion step so you can go back if you pick the wrong fields. Every step in the Applied Steps pane is reversible by deleting it.
  • When the source is JSON, use the expand icons rather than hand-writing formulas until the structure is clear, then tidy up the generated code.

Troubleshooting

If you get "The column 'X' of the table wasn't found", check the exact header text in the Applied Steps preview and correct the spelling in the formula. If the new columns are all null, the field names in your list do not match the record's actual field names, so click a record cell and compare the labels character by character.

If the expand icon is greyed out or missing, the column is not typed as Record. Click the type icon in the header and set it to Record, or check that the previous step actually produced records rather than text. If the query is slow, reduce the number of fields you extract and move filters earlier in the steps. If the load fails with duplicate column names, rename the clashing headers before closing and loading. When a step errors and you cannot see why, delete the step and rebuild it with the dialog, which avoids syntax slips in the formula.

Frequently Asked Questions

What is the difference between Table.ExpandRecordColumn and Table.ExpandTableColumn?

Table.ExpandRecordColumn works on a column of records, where each row holds one set of named fields. Table.ExpandTableColumn works on a column of tables, where each row holds a whole table, and it turns those rows into additional rows rather than additional columns.

Can I expand only some of the fields?

Yes. List only the fields you want in the third argument, or tick only those boxes in the expand dialog. The others are discarded.

Do I have to provide new column names?

No. The fourth argument is optional. Without it, the new columns take the field names from the record.

What happens if a record is missing a field?

The corresponding cell becomes null. The function does not fail, so check for nulls after expanding if your source data is inconsistent.

Can I expand a record inside a record?

Yes, but in two steps. Expand the outer record first, which leaves the inner field as another record column, then expand that column in a second step.

Does this work the same in Excel and Power BI?

The function and syntax are the same because both use the Power Query engine. Only the surrounding menus and the final load button differ between the two applications.