Record.FieldValues Function in Power Query
The Record.FieldValues function in Power Query M is used to retrieve all the values from a record as a list, in the order of the fields in the record.
Syntax
Record.FieldValues(record as record) as list
It takes a record as input and returns a list of the values (not keys!) in the same order they appear in the record.
Example: Return each row as a list item with field values.
Power Query M
// Start the 'let' block for defining the query steps let // Step 1: Create a table named 'MyTable' using Table.FromRecords // Each record has three fields: CustomerID, Name, and Phone MyTable = Table.FromRecords( { [CustomerID = 1, Name = "Ashish", Phone = "123-4567"], [CustomerID = 2, Name = "Katrina", Phone = "987-6543"], [CustomerID = 3, Name = "Alia", Phone = "543-7890"], [CustomerID = 4, Name = "Vicky", Phone = "676-8479"], [CustomerID = 5, Name = "Mohini", Phone = "574-8864"], [CustomerID = 6, Name = "Meenakshi", Phone = "574-8864"], [CustomerID = 7, Name = "Esha", Phone = "574-8864"], [CustomerID = 8, Name = "Anjali", Phone = "574-8864"] } ), // Step 2: Convert each row (record) in the table into a list of its values // Table.TransformRows applies a transformation to each row // Record.FieldValues(_) extracts all field values in a list format (ignores field names) AsList = Table.TransformRows(MyTable, each Record.FieldValues(_)) // Return the final list of lists as the output in AsList
The output will be shown in the following image:
Power Query M
{ {1, "Ashish", "123-4567"}, {2, "Katrina", "987-6543"}, {3, "Alia", "543-7890"}, {4, "Vicky", "676-8479"}, {5, "Mohini", "574-8864"}, {6, "Meenakshi", "574-8864"}, {7, "Esha", "574-8864"}, {8, "Anjali", "574-8864"} }
Example: Return the field values as a list item in the record.
Power Query M
let MyTable = Table.FromRecords( { [CustomerID = 1, Name = "Ashish", Phone = "123-4567"], [CustomerID = 2, Name = "Katrina", Phone = "987-6543"], [CustomerID = 3, Name = "Alia", Phone = "543-7890"], [CustomerID = 4, Name = "Vicky", Phone = "676-8479"], [CustomerID = 5, Name = "Mohini", Phone = "574-8864"], [CustomerID = 6, Name = "Meenakshi", Phone = "574-8864"], [CustomerID = 7, Name = "Esha", Phone = "574-8864"], [CustomerID = 8, Name = "Anjali", Phone = "574-8864"] } ), ReturnFieldValues = Record.FieldValues(MyTable{1}) in ReturnFieldValues
The output will be shown in the following image:
