Table.ExpandRecordColumn Function in Power Query M

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The Table.ExpandRecordColumn function takes a column where every cell holds a record (a set of named fields) and turns those fields into regular columns. You use it whenever a step leaves you with a column full of cells that just say Record.

Record columns show up when you look up a row, pick the top row of a group, or parse JSON data. In this article, I’ll show you how to expand them, rename the new columns, and deal with missing fields and missing matches.

Follow along with the example file

Table.ExpandRecordColumn Function Examples.xlsx

Download

Table.ExpandRecordColumn Function Syntax

Table.ExpandRecordColumn(table as table, column as text, fieldNames as list, optional newColumnNames as nullable list) as table
  • table – the table that has the column of records you want to expand.
  • column – the name of the record column, in double quotes (for example “Book Info”).
  • fieldNames – a list of the fields you want to turn into columns, such as {“Title”,”Author”}. The new columns appear in the same order as this list.
  • newColumnNames (optional) – a list of names for the new columns, in the same order as fieldNames. The new names can’t be the same as any column already in the table.

What it returns – a table where the record column is replaced by one column for each field you listed. The number of rows doesn’t change.

The Table.ExpandRecordColumn function is part of the core Power Query M library, so it works wherever Power Query does, including Excel 365, 2024, 2021, 2019, 2016, and Power BI.

When to Use the Table.ExpandRecordColumn Function

Use this function when you need to:

  • Pull columns from a row you looked up in another table
  • Show details of the top (or bottom) row in each group
  • Rename the new columns, or avoid a clash with a column you already have
  • Expand records where some rows don’t have every field
  • Add several calculated columns with one Table.AddColumn step
  • Flatten a record that has another record inside it
  • Expand every field of a parsed JSON column without typing the field names

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 Looked-Up Row

Let’s start with a simple example where I look up a row in another table and then expand it.

Below I have a Loans table (with Loan ID, Code, and Member) and a Books table (with Code, Title, and Author), and I want to show the book’s title and author next to each loan.

I’ve added a Book Info column that looks up each loan’s Code in the Books table, so every row now has the matching book’s row stored as a record.

Loans with a Book Info column holding the matching book's row as a Record

Each cell in the Book Info column shows the word Record, because it holds a whole row (Code, Title, and Author) 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.ExpandRecordColumn(BookInfo,"Book Info",{"Title","Author"})

Result: The Book Info column is replaced by a Title column (The Quiet Harbor, Garden Basics, The Quiet Harbor, Numbers at Work) and an Author column (Patricia Campbell, Henry Brown, Patricia Campbell, Chad Clark).

Title and Author columns expanded next to each loan

Here, BookInfo is the name of the previous step, “Book Info” is the column that holds the records, and {“Title”,”Author”} is the list of fields I want as columns. I left out Code because the Loans table already has it.

Here is the complete query, so you can see where the BookInfo step comes from:

let
Source = Excel.CurrentWorkbook(){[Name="Loans"]}[Content],
Books = Excel.CurrentWorkbook(){[Name="Books"]}[Content],
BookInfo = Table.AddColumn(Source,"Book Info",each Books{[Code=[Code]]}),
Expanded = Table.ExpandRecordColumn(BookInfo,"Book Info",{"Title","Author"})
in
Expanded

In the BookInfo step, Books{[Code=[Code]]} finds the row of the Books table whose Code matches the Code in the current row, and returns that row as a record. The Table.AddColumn function does this for every loan.

This kind of lookup keeps the rows in their original order.

But it needs exactly one match for each row, so a code that’s missing from the Books table (or listed twice) gives an error in that row. Example 4 shows how to handle a missing match.

Note that the new Title and Author columns have the type any (the ABC123 icon in the header), so add a Changed Type step after the Expanded step if you want them typed as text.

You can also match the two tables with a merge (Table.NestedJoin). A merge gives you a column of tables and not records, and you expand that with the Table.ExpandTableColumn function.

Example 2: Get the Top Row of Each Group (and Rename the Columns)

This next one uses the function with the Table.Group function.

Below I have a TrainerSessions table with each trainer’s Branch and the number of Sessions they ran, and I want to find the trainer with the most sessions in each branch.

I’ve grouped the data by Branch, and for each branch, the Top Row column holds the row with the highest Sessions value as a record.

One row per branch, with a Top Row column holding the top trainer's row as a Record

Here is the Group By step that creates the Grouped table:

= Table.Group(Source,{"Branch"},{{"Top Row",each Table.Max(_,"Sessions"),type record}})

The Table.Max function returns the whole row that has the largest value in the Sessions column, and type record tells Power Query that the new column holds records.

Now add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.ExpandRecordColumn(Grouped,"Top Row",{"Trainer","Sessions"},{"Top Trainer","Most Sessions"})

Result: Two rows, Downtown with Joanna Marshall (55 sessions) and Riverside with Robert Harris (51 sessions).

Top Trainer and Most Sessions columns, renamed while expanding

In the above formula, the fourth argument gives the new names, in the same order as the third argument. So Trainer becomes Top Trainer and Sessions becomes Most Sessions, and you don’t need a separate Table.RenameColumns step.

The newColumnNames list has to have the same number of names as the fieldNames list. If it’s shorter, you get the error “We expected newColumnNames to have the same number of items as fieldNames.”

If two trainers in a branch had the same top number, Table.Max would return only one of them. So check your data for ties if you need to show every top performer.

Example 3: Fix the “Field Already Exists” Error

This next one comes up when the record has a field with the same name as a column you already have.

Below I have an Enrollments table (with Name and Course) and a Courses table (with Course, Name, and Instructor), and I want to bring in the course name and the instructor.

I’ve added a Course Info column that looks up each Course code in the Courses table, the same way as in Example 1.

Enrollments with a Course Info column of course records that also contain a Name field

Both tables have a Name column. In Enrollments it’s the student’s name, and in Courses it’s the name of the course.

If you expand the Name field with its original name, Power Query stops with the error “The field ‘Name’ already exists in the record.” That’s because the table already has a Name column.

To fix it, add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.ExpandRecordColumn(CourseInfo,"Course Info",{"Name","Instructor"},{"Course Name","Instructor"})

Result: Two new columns, Course Name (Excel Basics, Data Analysis, Excel Basics, Pivot Tables) and Instructor (Megan Reed, Jocelyn Bailey, Megan Reed, Audrey Wallace), while the student Name column stays as it was.

Course Name and Instructor columns beside the student Name column

Here, the new names list renames the Name field to Course Name and keeps Instructor as it is. You have to give a name for every field in the list, even the ones you don’t want to change.

Example 4: Rows That Don’t Have a Match

Now let’s see what happens when a lookup doesn’t find anything.

Below I have a Tickets table (with Ticket, Agent, and Priority) and an Agents table (with Agent, Agent Name, and Team), and I want to add the agent’s name and team to each ticket.

One ticket, T-203, is assigned to AG-7, which isn’t in the Agents table.

I’ve added an Agent Info column that looks up each Agent code. The lookup ends with a question mark, which returns null instead of an error when no agent matches.

Tickets with an Agent Info column, showing null for T-203

For T-203, the Agent Info cell shows null instead of a record, because no agent has the code AG-7.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.ExpandRecordColumn(AgentInfo,"Agent Info",{"Agent Name","Team"})

Result: Agent Name and Team columns with Scott Hall/Tech, Regina Kelly/Billing, null/null, and Renee Stewart/Billing.

Agent Name and Team columns, with null for ticket T-203

When a cell in the record column is null, Table.ExpandRecordColumn simply puts null in every new column for that row. So T-203 stays in the table, and you can see it’s the one that needs an agent.

Here is the lookup step with the question mark:

= Table.AddColumn(Source,"Agent Info",each Agents{[Agent=[Agent]]}?)

Important: Without the question mark, the lookup gives the error “The key didn’t match any rows in the table.” for T-203, and that error shows up in the expanded columns too.

The question mark doesn’t help when a code appears twice in the lookup table. That still gives the error “The key matched more than one row in the table.”, so remove the duplicates first.

You can also get the same result with a merge (a left outer join keeps T-203), and then expand the tables with the Table.ExpandTableColumn function.

Example 5: Records That Don’t Have Every Field

Records in the same column don’t always have the same fields, especially when the data comes from a web form or an API.

Suppose you have four sign-ups, and each one has a Details record with the person’s Name, Email, and Phone, but some people skipped the email or the phone.

Create a new blank query (in Excel, go to Data > Get Data > From Other Sources > Blank Query), open the Advanced Editor (Home > Advanced Editor), and use this query:

let
Source = Table.FromRecords({[Signup=1,Details=[Name="Carl Owens",Email="carl.owens@example.com",Phone="555-0142"]],[Signup=2,Details=[Name="Gabriel Wright",Email="gwright@example.com"]],[Signup=3,Details=[Name="Matthew Hayes",Phone="555-0187"]],[Signup=4,Details=[Name="Justin Reynolds",Email="justin.r@example.com",Phone="555-0119"]]}),
Expanded = Table.ExpandRecordColumn(Source,"Details",{"Name","Email","Phone"})
in
Expanded

Result: 4 rows with Name, Email, and Phone columns. Gabriel Wright has null in Phone, and Matthew Hayes has null in Email.

Name, Email and Phone columns, with null where a sign-up skipped a field

Here, the Source step builds a table with a Details record for each sign-up, and Table.ExpandRecordColumn turns the three fields into columns.

When a record doesn’t have one of the fields you listed, you don’t get an error. That row just gets null in that column, so you can fill in the blanks or filter those rows in the next step.

Example 6: Add Several Columns From One Custom Column

You can also use Table.ExpandRecordColumn to add more than one calculated column at a time.

Below I have an Invoices table with a Date and an Amount for each invoice, and I want to add the Year, Month name, and Quarter of each date.

I’ve first set the Date column to the date type in a step called Typed, because dates from an Excel table come into Power Query with a time part.

Then I added a Date Parts column that calculates all three values for each row and stores them in one record.

Invoices with a Date Parts column holding a Year, Month and Quarter record

Here is the step that creates the Date Parts column:

= Table.AddColumn(Typed,"Date Parts",each [
Year=Date.Year([Date]),
Month=Date.MonthName([Date]),
Quarter="Q" & Text.From(Date.QuarterOfYear([Date]))
],type [Year=Int64.Type,Month=text,Quarter=text])

The square brackets after each create a record with three fields, Year, Month, and Quarter, using the Date.Year and Date.MonthName functions.

For Quarter, Date.QuarterOfYear gets the quarter number, Text.From turns it into text, and “Q” goes in front of it.

The last part, type [Year=Int64.Type,Month=text,Quarter=text], tells Power Query the data type of each field. Without it, the new columns would come out with the type any (the ABC123 icon in the header).

Now add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.ExpandRecordColumn(DateParts,"Date Parts",{"Year","Month","Quarter"})

Result: Three new columns. For 1/14/2026 you get 2026, January, and Q1, and for 11/3/2026 you get 2026, November, and Q4.

Year, Month and Quarter columns added from one record column

The expanded columns keep the types from the record, so Year is a whole number and Month and Quarter are text, with no Changed Type step needed.

The dates show as 1/14/2026 because my computer uses US regional settings. On a computer with UK settings, the same date shows as 14/01/2026, but the Year, Month, and Quarter values are the same. Here is the complete query:

let
Source = Excel.CurrentWorkbook(){[Name="Invoices"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"Date",type date},{"Amount",type number}}),
DateParts = Table.AddColumn(Typed,"Date Parts",each [
Year=Date.Year([Date]),
Month=Date.MonthName([Date]),
Quarter="Q" & Text.From(Date.QuarterOfYear([Date]))
],type [Year=Int64.Type,Month=text,Quarter=text]),
Expanded = Table.ExpandRecordColumn(DateParts,"Date Parts",{"Year","Month","Quarter"})
in
Expanded

Without the Typed step, the Date column would show 1/14/2026 12:00:00 AM.

You could also write three separate Table.AddColumn steps. The record route is handy when the values belong together, because you write and type them all in one place.

Follow along with the example file

Table.ExpandRecordColumn Function Examples.xlsx

Download

Example 7: Expand a Record Inside a Record

Sometimes a field inside a record is itself a record, which is common in JSON data. In that case, you expand twice.

Suppose you have three people, and each one has a Contact record with an Email and an Address, and the Address is another record with a City and a State.

Create a new blank query, open the Advanced Editor, and use this query:

let
Source = Table.FromRecords({[Name="Sydney Williams",Contact=[Email="sydney.w@example.com",Address=[City="Tucson",State="AZ"]]],[Name="Joshua Patterson",Contact=[Email="jpatterson@example.com",Address=[City="Raleigh",State="NC"]]],[Name="Holly Wood",Contact=[Email="holly.wood@example.com",Address=[City="Spokane",State="WA"]]]}),
ExpandedContact = Table.ExpandRecordColumn(Source,"Contact",{"Email","Address"}),
ExpandedAddress = Table.ExpandRecordColumn(ExpandedContact,"Address",{"City","State"})
in
ExpandedAddress

Result: 3 rows with Name, Email, City, and State columns. For example, Sydney Williams has sydney.w@example.com, Tucson, and AZ.

Name, Email, City and State after expanding Contact and then Address

Here, the ExpandedContact step turns Email and Address into columns. The new Address column still holds records, so the ExpandedAddress step expands it again into City and State.

Each Table.ExpandRecordColumn step only opens up one level of records. So the number of expand steps you need is the same as the number of levels you want to flatten.

Example 8: Expand All Fields Without Typing Their Names

When you list the field names yourself, any new field that shows up in the data later is left out. You can build the list with a formula instead.

Below I have a Devices table with a Specs column that holds JSON text, and I want each spec (CPU, RAM, Screen) in its own column, even though no device has all three.

I’ve parsed the Specs column into records with the Table.TransformColumns function and the Json.Document function, so the Parsed step has one record per device.

Devices with the Specs JSON parsed into a Record per device

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.ExpandRecordColumn(Parsed,"Specs",List.Union(List.Transform(Parsed[Specs],Record.FieldNames)))

Result: Three new columns, CPU, RAM, and Screen. Each device shows its own specs, with null where it doesn’t have that spec (like the CPU for Monitor C).

CPU, RAM and Screen columns built from every field name in the data

Here, Parsed[Specs] is the list of all the records in the Specs column. List.Transform runs Record.FieldNames on each record to get its field names, and List.Union combines those lists into one list with no repeats (CPU, RAM, Screen).

The columns come out in the order the fields first appear in the data. So if a new device has a field like Weight, the next refresh adds a Weight column on its own, with no change to the query.

Just make sure none of the field names matches a column you already have (Device in this case), or you’ll get the “already exists” error from Example 3.

Other Excel Articles You May Also Like:

All Power Query Functions

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.