Table.ExpandRecordColumn Function in Power Query

The Table.ExpandRecordColumn function expands a column of records into columns with each of the values.

Syntax

Table.ExpandRecordColumn(
table as table, 
column as text, 
fieldNames as list, 
optional newColumnNames as nullable list) as table

The function has the following parameters:

Example: The following is the code shows the table with many columns CustomerID, Name and Address. In this table the Address column is a column that contains records. The records contain the two columns State and Country.

Power Query M

let
  MyTable = Table.FromRecords(
    {
      [CustomerID = 1, Name = "Ashish", Address = [State = "Haryana", Country = "India"]], 
      [CustomerID = 2, Name = "Katrina", Address = [State = "Uttar Pradesh", Country = "India"]], 
      [CustomerID = 3, Name = "Alia", Address = [State = "Bihar", Country = "India"]], 
      [CustomerID = 4, Name = "Vicky", Address = [State = "TamilNadu", Country = "India"]], 
      [CustomerID = 5, Name = "Mohini", Address = [State = "Delhi", Country = "India"]], 
      [CustomerID = 6, Name = "Meenakshi", Address = [State = "Haryana", Country = "India"]], 
      [CustomerID = 7, Name = "Esha", Address = [State = "Uttar Pradesh", Country = "India"]], 
      [CustomerID = 8, Name = "Anjali", Address = [State = "Maharashtra", Country = "India"]]
    }
  )
in
  MyTable

The output of the above code is shown below:

Table.ExpandRecordColumn in Power Query

Now in the following code we are expanding the record columns and include the columns in our table.

Power Query M

let
  MyTable = Table.FromRecords(
    {
      [CustomerID = 1, Name = "Ashish", Address = [State = "Haryana", Country = "India"]], 
      [CustomerID = 2, Name = "Katrina", Address = [State = "Uttar Pradesh", Country = "India"]], 
      [CustomerID = 3, Name = "Alia", Address = [State = "Bihar", Country = "India"]], 
      [CustomerID = 4, Name = "Vicky", Address = [State = "TamilNadu", Country = "India"]], 
      [CustomerID = 5, Name = "Mohini", Address = [State = "Delhi", Country = "India"]], 
      [CustomerID = 6, Name = "Meenakshi", Address = [State = "Haryana", Country = "India"]], 
      [CustomerID = 7, Name = "Esha", Address = [State = "Uttar Pradesh", Country = "India"]], 
      [CustomerID = 8, Name = "Anjali", Address = [State = "Maharashtra", Country = "India"]]
    }
  ), 
  Return = Table.ExpandRecordColumn(
    MyTable, 
    "Address", 
    {"State", "Country"}, 
    {"Customer State", "Customer Country"}
  )
in
  Return

The output of the above code is shown below:

Table.ExpandRecordColumn function in Power Query