Power Query Record.FromTable Function Guide
In this article
The Record.FromTable function in Power Query transforms a table consisting of two columns—one for field names and one for values—into a single Record object. This is primarily used when you have a vertical list of parameters, settings, or attributes that you want to convert into a horizontal record format to easily access specific values using the [FieldName] syntax or to merge them into other records.
What You'll Need
- Microsoft Excel or Power BI Desktop with Power Query installed.
- A table containing exactly two columns: the first column must contain the intended record field names (text), and the second column must contain the corresponding values.
- Basic familiarity with the Power Query Editor and the Formula Bar.
Step-by-Step
- Prepare Your Source Table: Ensure your data is in a table format. The table must have exactly two columns. For example, if you are creating a configuration record, Column 1 should be named "Parameter" (containing values like "API_Key", "Timeout", "URL") and Column 2 should be named "Value" (containing the actual settings). If your table has more than two columns, the function will return an error.
- Load Data into Power Query: Select your table in Excel or Power BI, go to the Data tab, and select Get Data > From Table/Range. This opens the Power Query Editor.
- Open the Advanced Editor or Formula Bar: While you can use the GUI for many tasks,
Record.FromTableis an M-code function that is typically entered directly into the formula bar or the Advanced Editor. To see the formula bar, ensure View > Formula Bar is checked. - Apply the Function: Create a new step by clicking the
fxicon next to the formula bar. Replace the default formula with= Record.FromTable(PreviousStepName). Replace "PreviousStepName" with the name of the step that contains your two-column table (usuallySourceorChanged Type). - Verify the Result: After pressing Enter, the table icon in the query preview will change to a Record icon. You will now see a list of fields and values. You can click on any field to see its specific value in the preview pane.
- Accessing Record Values: To use a value from this record in a later step, use the record name followed by the field name in square brackets. For example, if your step is named
MySettingsand you have a field called "URL", you would reference it asMySettings[URL]. - Closing and Loading: Once the record is created and verified, you can use it as a reference for other queries or load the result back into your model.
Common Mistakes
One of the most frequent errors is attempting to use Record.FromTable on a table with more than two columns. The function is strictly designed for a key-value pair structure. If your table contains a third column (such as a category or a date), the function will fail immediately. You must first remove the unnecessary columns using the Remove Columns transformation before applying the function.
Another common mistake is having duplicate values in the first column. Since a Record in Power Query cannot have two fields with the exact same name, providing a table with duplicate keys will result in an error. You must ensure that the "Field Name" column contains unique values. If duplicates exist, you should use the Group By feature or Remove Duplicates on the first column before converting the table to a record.
Users also frequently forget that the first column must be of the Text data type. If the first column contains numbers or dates that are intended to be field names, Power Query may throw a type mismatch error. Always explicitly set the first column to Text using the Transform > Data Type > Text menu before calling the function.
Tips
To make your queries more dynamic, use Record.FromTable to create a "Settings" table in Excel. By storing your API keys, folder paths, or date ranges in a small Excel table and converting them to a record in Power Query, you can update your entire report's parameters by simply changing a cell in the spreadsheet without ever opening the Power Query Editor.
If you need to convert a record back into a table later in your workflow, you can use the Record.ToTable function. This symmetry allows you to move data between a structured table (good for filtering and cleaning) and a record (good for fast lookups and parameterization).
When dealing with large datasets, remember that records are stored in memory. While Record.FromTable is incredibly efficient for small configuration tables, avoid using it to convert massive data tables into a single record, as this can lead to performance degradation or memory errors during the refresh process.
Troubleshooting
If you encounter an error stating that the table must have exactly two columns, check your previous step. Often, a "Changed Type" step might have added a hidden column or you might have forgotten to remove an index column. Go back to the step immediately preceding the Record.FromTable call and verify the column count.
If you see an error regarding duplicate field names, use the following sequence: Select the first column > Right-click > Remove Duplicates. This ensures the function has a unique key for every record field. If you need to keep the duplicates, you must reconsider if a Record is the right data structure, as Tables or Lists are better suited for non-unique keys.
If the record is created but you cannot find the specific field you are looking for, check for trailing or leading spaces in your source table. A field named "URL " (with a space) is different from "URL". Use the Transform > Format > Trim function on the first column of your table before converting it to a record to ensure clean field names.
In cases where the function returns a "null" value unexpectedly, verify that the second column of your source table actually contains data. If the value cell is empty, the record field will be created, but its value will be null. Use the Replace Values transformation to fill in blanks with a default value if necessary.
Frequently Asked Questions
Can I use this function to pivot data?
While it resembles a pivot operation, Record.FromTable creates a single Record object, not a new Table. If you want to transform a vertical table into a horizontal table with multiple rows, you should use the Pivot Column feature found in the Transform tab.
Does the order of the rows in the table matter?
The order of the rows determines the order in which the fields appear within the record. While this doesn't affect how you access the data via [FieldName], it can affect how the record looks in the preview window or how it behaves if you later convert it back to a table.
What happens if the second column contains different data types?
Records in Power Query are flexible and can hold mixed data types. One field can be a number, the next a text string, and the third a date. The function will preserve the data type of the value in the second column for each respective field.
Can I use Record.FromTable within a custom column?
Yes, but be careful. If you use it inside a custom column, you will create a "Record" cell within every row of your table. This is useful for creating nested data structures (like JSON-style objects) that can be expanded later using the Expand button on the column header.
Is there a limit to how many fields a record can have?
There is no hard-coded limit on the number of fields, but practical limits are imposed by your system's available memory. For a few hundred parameters, it is extremely fast; for tens of thousands, it may slow down your query refresh.