Record.Field Function (Power Query M)

If you want to pull a single value out of a record by naming the field you want, Record.Field is the function for that.

It takes a record and a field name as text, and hands back the value stored under that field. Because the field name is just text, you can hold it in a variable and decide it at runtime in Power Query.

Syntax of Record.Field Function

Record.Field(record as record, field as text) as any

where

  • record (required, record). The record you want to read a value from.
  • field (required, text). The name of the field to fetch, given as a text value.

Returns: the value of that field (type any). If the field is not in the record, it raises an error.

In plain terms, you give it a record and a field name, and it returns whatever value sits under that name.

Example 1: Pull one field from an inline record

Read the Author field out of a small book record.

let
Book = [Title="The Silent Harbor", Author="R. Mehta", Price=14.5],
Result = Record.Field(Book,"Author")
in
Result

Result: R. Mehta

The field name "Author" matches a field in Book, so its value comes back.

Example 2: Use a dynamic field name held in a variable

Here the field name lives in a variable instead of a hard-coded string.

let
Book = [Title="The Silent Harbor", Author="R. Mehta", Price=14.5],
FieldToGet = "Price",
Result = Record.Field(Book,FieldToGet)
in
Result

Result: 14.5

FieldToGet resolves to "Price", so Record.Field returns the price. This is the case where record[Field] shorthand will not work.

Example 3: Use Record.Field inside Table.AddColumn

When you add a column, each gives you the current row as a record in _. You can pick a field from it by name.

Here is the starting Books table:

TitleAuthorPrice
The Silent HarborR. Mehta14.5
TidelineK. Osei9.99
Northwind NotesL. Park22
let
Source = Excel.CurrentWorkbook(){[Name="Books"]}[Content],
PickField = "Author",
Added = Table.AddColumn(Source,"Picked",each Record.Field(_,PickField))
in
Added

The new Picked column copies each row’s Author value:

TitleAuthorPricePicked
The Silent HarborR. Mehta14.5R. Mehta
TidelineK. Osei9.99K. Osei
Northwind NotesL. Park22L. Park

Since PickField is text, you could swap it to "Price" and the column would follow. To rename that new column afterward, reach for Table.RenameColumns.

Example 4: Build the field name dynamically per row

The field to read can change row by row. Here each row’s own Pick column says which column to grab.

Here is the starting Sensors table:

StationQ1Q2Pick
North1823Q2
South3127Q1
East1219Q2
let
Source = Excel.CurrentWorkbook(){[Name="Sensors"]}[Content],
Chosen = Table.AddColumn(Source,"Reading",each Record.Field(_,[Pick]))
in
Chosen

The Reading column pulls the value named in that row’s Pick:

StationQ1Q2PickReading
North1823Q223
South3127Q131
East1219Q219

For the North row, [Pick] is "Q2", so Record.Field returns 23. If you wanted to reshape those values instead of just copying them, Table.TransformColumns is the column-level tool for that.

Example 5: Read a field whose name has a space

Field names with spaces need the quoted identifier #"..." when you define them, and a plain text string when you read them.

let
Order = [#"Order ID"="A-1007", #"Total Due"=248.75],
Result = Record.Field(Order,"Total Due")
in
Result

Result: 248.75

The text "Total Due" matches the field cleanly, with no special escaping needed in the second argument.

Things to keep in mind with Record.Field

  • Use record[Field] for a fixed name, Record.Field for a variable one. The [Field] shorthand needs the name written into the code. When the name lives in a variable or column, like Examples 2 and 4, you need Record.Field.
  • A missing field raises an error. Asking for a field that is not there gives Expression.Error: The field 'X' of the record wasn't found. Use Record.FieldOrDefault(record,field,default) to return a fallback instead.
  • Field names are case-sensitive. Record.Field(r,"author") will not find a field named Author. Match the case exactly.

List of All Power Query Functions

Related Power Query Functions / Articles:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.