Power Query Record.FieldValues: How to Use It
In this article
To use the Record.FieldValues function in Power Query, you pass a single record as an argument, and it returns a list containing all the values from that record. This is primarily used when you need to extract data from a nested record structure into a format that can be expanded into a list or a table, allowing you to bypass the need to manually reference every individual field name.
In Power Query (M language), a Record is a set of fields, where each field has a name and a value. While you can often access a specific value using the syntax Record[FieldName], this requires you to know the name of the field beforehand. Record.FieldValues is the dynamic solution for when the field names are unknown, change frequently, or when you simply want to grab every piece of data inside the record regardless of what the columns are called. This is particularly useful in data engineering workflows where schema drift—the changing of column names in a source system—can break traditional hard-coded queries.
What You'll Need
- Microsoft Excel or Power BI Desktop with the Power Query editor installed.
- A data source containing at least one column with Record values. This is most common when importing JSON, XML, or REST API responses where hierarchical data is nested within a single cell.
- A basic understanding of the Power Query interface and the concept of M code, specifically how to use the Custom Column dialog.
Step-by-Step
- Identify the Record Column: Open your Power Query editor. Look for a column that contains the word "Record" in its cells. In the preview window, if you see a cell that doesn't display a simple value like "10" or "Apple" but instead shows the word "Record" in yellow or gray text, you have found your target. This indicates that the cell contains a structured object rather than a primitive data type.
- Open the Advanced Editor: To understand how the function integrates into your existing steps, go to the Home tab in the Power Query ribbon and click on Advanced Editor. This displays the M code that drives your query. While you don't necessarily need to write code here, seeing the structure helps you understand how functions are nested within steps like
letandin. - Create a Custom Column: Instead of manually typing long M scripts, use the built-in interface. Go to the Add Column tab on the ribbon and select Custom Column. This opens a dialog box where you can define a new column based on a formula.
- Enter the Function Syntax: In the Custom Column dialog box, you will see a formula bar. To use Record.FieldValues, you must reference the name of the column containing the record using square brackets. If your column is named
SourceData, your formula must be:= Record.FieldValues([SourceData]). The square brackets are critical; they tell Power Query to look at the value within the current row of that specific column. - Apply and Observe the Result: Click OK. You will notice a new column appears. Instead of seeing the expanded record view (which usually shows individual columns), you will see the word "List" in every cell. This is because Record.FieldValues has transformed the record's key-value pairs into a simple, ordered list of values.
- Expand the List: To turn these values into usable data, click the two-way arrow icon (the expand icon) at the top right of the new List column header. You have two main choices: "Expand to New Rows" will create a new row for every single value in the list, effectively duplicating the other data in that row. "Extract Values" is another option, but it usually converts the list into a single comma-separated text string, which is less useful for mathematical analysis.
- Convert to Table (Advanced): If your goal is to have a clean table where each record's values become columns, you might find it more efficient to use
Table.FromRecords. However, Record.FieldValues is the specific engine used when you need to perform operations on the values themselves—such as finding the maximum value in a record or summing them up—without caring about what the headers are named.
Common Mistakes
The most frequent mistake is attempting to use Record.FieldValues on a column that is not actually a Record type. If you try to run this function on a Text, Number, or Date column, Power Query will return a DataFormat.Error stating that the argument provided is not a record. Always verify the data type in the column header or by looking at the cell preview before writing the formula. If the column says "Text" or "Any" but contains strings that look like records, you may first need to use Json.Document to parse the text into an actual record object.
Another common error is forgetting the square brackets around the column name. In the M language, writing Record.FieldValues(SourceData) (without brackets) tells the engine to look for a step or a variable named SourceData. Since SourceData is a column name, not a step name, the function will fail. You must use [SourceData] to indicate you are referencing the content of the current row.
Users also often confuse Record.FieldValues with Record.FieldNames. These are two distinct functions with opposite outputs. Record.FieldNames returns a list of the keys (the labels or headers), whereas Record.FieldValues returns the actual data contained within those keys. If you find your resulting list is full of words that look like column headers instead of the numbers or text you expected, you have used the wrong function.
Lastly, be aware of the order of values. Record.FieldValues returns a list based on the internal order of the record. While records in Power Query are generally ordered, relying on a specific index (like "the third value in the list") can be dangerous if the source data structure changes. It is always safer to use field names whenever possible, and only use Record.FieldValues when the field names are truly unknown or irrelevant.
Tips
Use Record.FieldValues when dealing with highly dynamic JSON data. If you are consuming an API where the keys change frequently—for example, a weather API that adds new metrics like "humidity" or "uv_index" without warning—Record.FieldValues allows your query to remain robust. Instead of your query breaking because a new column appeared that wasn't in your original "Expand" step, you can use this function to grab all available metrics dynamically.
Another powerful tip is combining Record.FieldValues with List functions. For example, if you have a record containing several numeric values and you want to find the highest one, you can write a custom column formula like: List.Max(Record.FieldValues([MyRecordColumn])). This is much faster than expanding the record into five different columns and then running a Max function across those columns.
When working with large datasets, be cautious about expanding lists to new rows. If you have a table with 1,000,000 rows and each record contains 10 values, expanding the list to new rows will result in a table with 10,000,000 rows. This can significantly increase memory usage and slow down your refresh times. In such cases, consider if you can perform your calculations within the list itself using List.Sum or List.Average before expanding.
Troubleshooting
If you encounter an error, follow these steps in order:
- Check the Data Type: Click on the column header of the column you are referencing. Look at the icon to the left of the name. If it is not the "Record" icon (which looks like a small table with a single row), the function will not work. If the data looks like a record but is typed as "Text," go to the Transform tab and change the type to "Record" (though you may need to use
Json.Documentfirst). - Verify the Formula Syntax: Check for the square brackets. Ensure there are no typos in the column name. Power Query is case-sensitive, so
[userdata]is not the same as[UserData]. - Test with a Single Row: To isolate whether the issue is with the function or the volume of data, try filtering your table to show only the first 10 rows. If the error disappears, the issue is likely related to a specific malformed record further down in your dataset.
- Inspect the Record Structure: Click in the empty white space next to the word "Record" in a cell. A preview pane will appear at the bottom of the screen. Use this to confirm that the record actually contains the values you think it does and that it isn't an empty record
[].
Frequently Asked Questions
Can Record.FieldValues handle null values?
Yes, if a field within the record contains a null, the resulting list will simply contain a null at that position. It will not cause the function to fail, but you should ensure your subsequent steps (like mathematical operations) are prepared to handle nulls using functions like List.NonNullCount or List.RemoveNulls.
Does the order of values in the list match the column order?
The order in the list corresponds to the order of the fields within the record. In most cases, this follows the order in which the record was constructed, but because records are technically unordered collections of fields, you should never rely on a specific index position for critical data logic.
What is the difference between Record.FieldValues and Table.Column?
Record.FieldValues operates on a single record (one row) to turn its fields into a list. Table.Column operates on an entire table to extract all values from one specific named column into a list. They serve different purposes in the data transformation pipeline.
How do I convert the resulting list back into a record?
You generally wouldn't want to do this, as you would lose the field names (the keys). If you have a list of values and want to turn them into a record, you would need a second list of names to pair them with, using a function like Record.FromList.