Power Query Record.FromList Function Guide
In this article
The Record.FromList function in Power Query (M language) converts a list of values into a record by pairing those values with a corresponding list of field names. This is primarily used when you have data in a vertical or list format that needs to be transformed into a structured record for easier access to specific fields, merging into tables, or creating custom JSON-like objects within your data transformation pipeline.
What You'll Need
- Microsoft Excel or Power BI Desktop.
- Access to the Power Query Editor (Get Data > Launch Power Query Editor).
- A basic understanding of the Power Query M language (specifically how lists and records are represented).
- An existing data source or a blank query where you can enter M code.
Step-by-Step
- Open the Power Query Editor: Launch Power BI Desktop or Excel. In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click Transform Data on the Home ribbon.
- Create a Blank Query: On the Home tab, select New Source > Blank Query. This provides a clean slate to write the M code manually.
- Open the Advanced Editor: To see the full code structure, click the View tab and select Advanced Editor. This is where you will define your lists and apply the function.
- Define the Value List: Create a list containing the data you want to store. In M, lists are wrapped in curly brackets. For example:
ValueList = {"John Doe", 30, "New York"}. - Define the Field Name List: Create a second list containing the names you want to assign to each value. This list must be the same length as the value list. For example:
NameList = {"Name", "Age", "City"}. - Apply the Record.FromList Function: Use the function syntax
Record.FromList(values, names). In your query, this would look like:Result = Record.FromList(ValueList, NameList). - Verify the Result: Click Done in the Advanced Editor. You will now see a Record object in the query preview. Clicking on the record allows you to see the individual fields (Name, Age, City) and their associated values.
- Convert to Table (Optional): If you need this record to be part of a larger dataset, go to the Transform tab and select To Table. This converts the record's fields into columns and its values into a single row.
Common Mistakes
One of the most frequent errors is a mismatched list length. The Record.FromList function requires a one-to-one mapping. If your value list contains five items but your field name list only contains four, Power Query will throw an error because it cannot assign a name to the fifth value. Always ensure that List.Count(ValueList) = List.Count(NameList).
Another common mistake is incorrect data typing. While records can hold mixed types, if you plan to convert the resulting record into a table, inconsistent types across different records in a list can lead to "Any" type columns, which may slow down performance or cause errors during later aggregation steps. Ensure your lists are cleaned and typed before passing them into the function.
Users also often confuse Record.FromList with Record.FromTable. While both create records, Record.FromList specifically requires two separate lists (values and keys). If your data is already in a two-column table format, using Record.FromList requires you to first extract those columns into separate lists using Table.Column, which is an unnecessary extra step.
Tips
Dynamic Field Generation: Instead of hard-coding your field names, you can generate them dynamically. For example, if you have a list of 100 values, you can use List.Numbers(1, 100) and then use List.Transform to turn those numbers into strings like "Field1", "Field2", etc. This prevents the need to manually type out long lists of headers.
Nesting Records: You can use Record.FromList inside another function to create a list of records. By using List.Transform on a table of data, you can convert each row into a record. This is incredibly useful when preparing data for API calls (JSON payloads) where a specific record structure is required for each entry.
Using List.Zip: If your data is already paired in a list of lists (e.g., ), you can use List.Zip or List.Transform to split them into the two distinct lists required by Record.FromList . This allows you to maintain the relationship between the key and the value throughout your transformation steps.
Performance Optimization: When dealing with very large datasets, avoid creating thousands of individual records using this function in a loop. Instead, try to perform bulk table operations. Records are powerful for single-row lookups or API structures, but for massive data processing, the Table format is significantly more optimized in the Power Query engine.
Troubleshooting
Error: "The number of elements in the lists must be the same."
This is the most common error. To fix this, check the count of both lists. You can do this by creating temporary steps in the Power Query editor: Count1 = List.Count(ValueList) and Count2 = List.Count(NameList). If they differ, identify which list is missing data. If the values list is longer, you may need to truncate it using List.FirstN or add dummy names to the name list.
Error: "Expression.Error: The field 'X' of the record was not found."
This usually happens after you have created the record and are trying to access a field. Check for typos in your name list. Remember that M is case-sensitive; "Name" is not the same as "name". If your name list is generated from another source, use Text.Trim to remove accidental leading or trailing spaces that might be hiding in the field names.
Result is a "Record" object but I want a Table:
If your output looks like a single clickable "Record" cell, it is working as intended. To expand this, you must use the Table.FromRecords function if you have a list of records, or simply click the "To Table" button in the Transform ribbon if you have a single record. If you are writing M code, Record.ToTable(Result) will convert the record into a two-column table of Attribute and Value.
Values are appearing as "null":
Check your source lists. If the value list contains nulls, the record will reflect that. If the record is completely empty, ensure that the lists you are passing into the function are not empty lists {}. Use the query preview to inspect the lists immediately before the Record.FromList step.
Frequently Asked Questions
Is Record.FromList case-sensitive?
Yes, the M language is case-sensitive. The field names you provide in the name list will be exactly as written. If you name a field "CustomerID", you cannot retrieve it using "customerid".
Can I use this function to create a JSON object?
While Record.FromList creates a Power Query Record, these records are the internal representation of JSON objects. When you export data or use it in a web request, these records are converted directly into JSON format.
What happens if the name list contains duplicate names?
Power Query records cannot have duplicate field names. If your name list contains the same string twice, the function will return an error because a record must have unique keys to identify its values.
Can the value list contain other lists or records?
Yes. The value list can contain any data type, including other lists, records, or tables. This allows you to create complex, nested record structures.
Is there a limit to how many fields a record can have?
There is no hard-coded limit on the number of fields, but extremely large records (thousands of fields) can degrade performance and make the Power Query interface sluggish when previewing the data.
How do I access a specific value from the resulting record?
You can access a value using the square bracket notation. If your record is named MyRecord and the field is "Name", you would use to extract the value.