Record.FieldValues 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 Record.FieldValues function in Power Query takes a record and gives you all its values as a list. The field names are dropped, and the values stay in the same order as the fields.

Where it really helps is inside a table. Each row of a table is a record, so you can turn a whole row into a list and then total it, join it, or check it for a value.

In this article, I’ll show you how it works, starting with a single record and moving on to row-by-row calculations in a table.

Follow along with the example file

Record.FieldValues Function Examples.xlsx

Download

Record.FieldValues Function Syntax

Record.FieldValues(record as record) as list
  • record – the record you want the values from. A record is a set of named values in square brackets, such as [Item="Pen",Price=2]. In a table, each row is a record, and its column names are the field names.

What it returns: A list of the record’s values, in the same order as its fields. Blank (null) values stay in the list, so a record with five fields always gives you five items.

The Record.FieldValues function is part of the core Power Query M library, so it works anywhere you can use Power Query, including Excel for Microsoft 365 and Power BI.

When to Use the Record.FieldValues Function

Use this function when you need to:

  • Get all the values from a record as a list
  • Pull one row of a table out as a list of values
  • Add up the numbers across a row, including columns added later
  • Join the text in a row into one value, skipping the blanks
  • Check whether any column in a row has a certain value
  • Remove rows where every cell is blank
  • Find which column holds the highest value in each row

Example 1: Get the Values from a Record

Let’s start with the basics. Suppose you have a record with the details of a training course, and you want just the values, without the field names.

In Excel, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor, open the Advanced Editor (Home > Advanced Editor) and use this code:

let
CourseRecord = [Course="Excel Basics",Level="Beginner",Hours=6],
Result = Record.FieldValues(CourseRecord)
in
Result

Result: A list with Excel Basics, Beginner, and 6

Record.FieldValues returns a list with Excel Basics, Beginner and 6

Here, the CourseRecord step holds a record with three fields: Course, Level, and Hours. Record.FieldValues returns their values as a list, in the same order as the fields.

The field names are gone from the result. If you only need one value, such as the Hours, the Record.Field function gets it by name.

If you want the names instead, the Record.FieldNames function returns them as a list in the same order, and Example 7 uses both together.

There’s also a Record.ToList function that returns exactly the same list.

It doesn’t matter which one you use. This article sticks with Record.FieldValues because its name matches Record.FieldNames.

In the example file, Example 1 has no worksheet, because the record is typed right inside the query. To open it, go to Data > Queries & Connections and double-click the query name.

Example 2: Get One Row of a Table as a List

Here’s where records come from in real data. Below is a product list in an Excel Table named Products, and I want all the details of the product with the SKU CH-310 as a list.

Products table with SKU, Product, Category and Price for five products

Create a new blank query, open the Advanced Editor, and use this code. The Source line reads the Products table by its name, so you don’t have to load it into Power Query first.

let
Source = Excel.CurrentWorkbook(){[Name="Products"]}[Content],
Result = Record.FieldValues(Source{[SKU="CH-310"]})
in
Result

Result: A list with CH-310, Office Chair, Seating, and 149

The CH-310 row as a list: CH-310, Office Chair, Seating, 149

Here, Source{[SKU="CH-310"]} finds the row where the SKU column is CH-310 and returns that row as a record. Record.FieldValues then turns it into a list of the four values in that row.

This lookup needs exactly one matching row. If no row has that SKU, you get the error “The key didn’t match any rows in the table”, and if two rows have it, you get “The key matched more than one row in the table”.

Example 3: Add Up the Numbers Across Each Row

This next one comes up a lot. Below is a log of the hours each volunteer worked over four weeks, and I want the total for each person in a new Total Hours column.

VolunteerHours table with each volunteer's hours for Week 1 to Week 4

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

let
Source = Excel.CurrentWorkbook(){[Name="VolunteerHours"]}[Content],
#"Added Total" = Table.AddColumn(Source,"Total Hours",each List.Sum(List.Skip(Record.FieldValues(_),1)),type number)
in
#"Added Total"

Result: A new Total Hours column (26, 21, 37, 18, 30, and 22)

A new Total Hours column: 26, 21, 37, 18, 30, 22

Here, the Table.AddColumn function adds the Total Hours column, working out its value one row at a time. The each keyword runs the expression after it for every row, and the underscore (_) stands for the current row, which is a record.

So Record.FieldValues(_) turns each row into a list, such as Christina Patterson, 6, 8, 5, and 7. The name is text, and the List.Sum function can’t add text, so the List.Skip function drops the first item before the numbers are added up.

For Christina Patterson, that’s 6 plus 8 plus 5 plus 7, which gives 26.

The nice part is that you never typed a week column’s name. If a Week 5 column gets added to the table, refresh the query and it’s included in the total.

List.Skip goes by position, so this only works when the name is in the first column. If your label column could be anywhere, use Record.FieldValues(Record.RemoveFields(_,"Volunteer")) instead, which removes the Volunteer field by its name.

Example 4: Join the Values in a Row into One Text

Here’s a text version of the same idea. Below is a list of employees with up to three skills each, and I want all of a person’s skills in one cell, separated by commas, in a new All Skills column.

Skills table with up to three skills per employee, some cells blank

Some people have only one or two skills, so some cells are blank. We want those blanks skipped, not shown as extra commas.

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

let
Source = Excel.CurrentWorkbook(){[Name="Skills"]}[Content],
#"Added Skills" = Table.AddColumn(Source,"All Skills",each Text.Combine(List.Skip(Record.FieldValues(_),1),", "),type text)
in
#"Added Skills"

Result: A new All Skills column, such as “Excel, Power BI, SQL” for Janet Stewart and “Excel” for Carlos Mitchell

A new All Skills column joins each employee's skills with commas

Here, Record.FieldValues turns each row into a list, and List.Skip drops the employee’s name. Then the Text.Combine function joins what’s left with a comma and a space.

Blank cells come into Power Query as null, and Text.Combine skips nulls. That’s why Carlos Mitchell gets just “Excel”, with no trailing commas.

Text.Combine only works with text, though. If one of the columns held a number, you’d get an error like “We cannot convert the value 1 to type Text”, so this works best when every column you join is text.

Example 5: Flag Rows Where Any Column Has a Value

Now let’s check a whole row for one value. Below is a quality check log where each batch is marked Pass or Fail on three checks, and I want a Status column that says Needs Review when any check failed.

Inspections table with Pass or Fail for Seal, Label and Weight

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

let
Source = Excel.CurrentWorkbook(){[Name="Inspections"]}[Content],
#"Added Status" = Table.AddColumn(Source,"Status",each if List.Contains(Record.FieldValues(_),"Fail") then "Needs Review" else "OK",type text)
in
#"Added Status"

Result: A new Status column with Needs Review for B-1042, B-1044, and B-1046, and OK for the rest

A new Status column: Needs Review for B-1042, B-1044 and B-1046

Here, Record.FieldValues turns each row into a list, and the List.Contains function checks whether “Fail” is anywhere in that list. If it is, the row gets Needs Review, otherwise it gets OK.

B-1044 failed two checks, but it still gets one Needs Review, because List.Contains only asks whether “Fail” is there at all.

This check is case-sensitive, so a cell that says “fail” in lowercase won’t be caught. To ignore case, add Comparer.OrdinalIgnoreCase as a third argument: List.Contains(Record.FieldValues(_),"Fail",Comparer.OrdinalIgnoreCase).

Example 6: Remove Rows Where Every Cell Is Blank

This one is handy for cleaning up data. Below is a contact list with a few completely empty rows in it, and I want to remove those empty rows but keep everything else.

Contacts table with two completely blank rows

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

let
Source = Excel.CurrentWorkbook(){[Name="Contacts"]}[Content],
#"Removed Blank Rows" = Table.SelectRows(Source,each List.NonNullCount(Record.FieldValues(_))>0)
in
#"Removed Blank Rows"

Result: The same table with the two empty rows removed, leaving four contacts

The blank rows are removed, leaving four contacts

Here, the Table.SelectRows function keeps only the rows where the condition is true. For each row, Record.FieldValues makes a list of its values, and the List.NonNullCount function counts the ones that aren’t null.

An empty row has a count of 0, so it’s removed. Linda Allen’s row has no phone number, but it still has a name and a city, so its count is 2 and it stays.

Important: List.NonNullCount counts empty text (“”) as a value, and data from CSV files or formulas often has “” in blank-looking cells. If those rows don’t go away, use each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_),{"",null})) as the condition instead.

That condition takes the row’s values and removes every empty text and null from the list. If nothing is left, the row was blank, so it’s removed, and every other row stays.

Example 7: Find the Column with the Highest Value in Each Row

Here’s a more advanced one that uses the field names too. Below is a table of quarterly sales for six products, and I want a Best Quarter column that shows which quarter had the highest sales for each product.

QuarterlySales table with Q1 to Q4 sales for six products

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

let
Source = Excel.CurrentWorkbook(){[Name="QuarterlySales"]}[Content],
#"Added Best Quarter" = Table.AddColumn(Source,"Best Quarter",each Record.FieldNames(_){List.PositionOf(Record.FieldValues(_),List.Max(List.Skip(Record.FieldValues(_),1)))},type text)
in
#"Added Best Quarter"

Result: A new Best Quarter column (Q3, Q4, Q3, Q1, Q2, and Q4)

A new Best Quarter column: Q3, Q4, Q3, Q1, Q2, Q4

This formula is easier to follow from the inside out. First, List.Skip(Record.FieldValues(_),1) gives the four sales numbers without the product name, and the List.Max function finds the highest one.

The product name has to go first, because on a list that mixes text and numbers, List.Max returns the text. So without List.Skip, you’d get “Trail Shoes” as the highest value instead of 610.

Then the List.PositionOf function finds where that highest number sits in the full list of values (the full list on purpose, so the position matches the column names).

For the Trail Shoes, the highest is 610, which is at position 3 (positions start at 0, and the product name is at position 0).

Finally, Record.FieldNames returns the column names in the same order (Product, Q1, Q2, Q3, Q4), and {3} picks the name at position 3, which is Q3.

This works because the names list and the values list line up one-to-one. Record.FieldValues and Record.FieldNames always return their items in the same field order.

If two quarters tie for the highest value, List.PositionOf returns the first one it finds, so you get the earlier quarter.

Other Excel Articles You May Also Like:

  • Record.SelectFields – Use Record.SelectFields in Power Query M to keep only the fields you need from a record.
  • Table.ToRows – Use Table.ToRows in Power Query M to turn table rows into lists.
  • Table.FromRecords – Use Table.FromRecords in Power Query M to build a table from records.
  • Table.ToList – Use Table.ToList in Power Query M to turn each table row into one value.
  • Table.ExpandRecordColumn – Use Table.ExpandRecordColumn in Power Query M to turn a record column into columns.
  • List.RemoveNulls – Use List.RemoveNulls in Power Query M to drop null values from a list.
  • List.AnyTrue – Use List.AnyTrue in Power Query M to check if any value is true.
  • List.First – Use List.First in Power Query M to get the first item in a list.

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.