Power Query Record.AddField: How to Use It
In this article
Record.AddField adds a new field to an existing record in Power Query, returning a new record with the added field and value. You use it inside a custom column or a step in the Advanced Editor, typically to enrich structured data without flattening it. The function is part of the M language and works in Power Query for Excel, Power BI, and Dataflows. Before you start, you need a query with a column that contains records (or a step that produces a record) and a basic understanding of the Advanced Editor.
What You'll Need
- Power Query Editor open in Excel or Power BI Desktop.
- A query that includes a record column or a record value (for example, from a JSON source or a grouped table).
- Familiarity with the Advanced Editor (Home > Advanced Editor) or the formula bar.
- The exact field name you want to add and the value or expression that produces it.
Step-by-Step
- Open the query in Power Query Editor. In Excel, go to Data > Get Data > Launch Power Query Editor; in Power BI Desktop, click Transform data. Select the query that contains the record column.
- Inspect the record column. Click the cell that contains a record to see its fields in the preview pane. Note the field names you want to keep and the new field name you will add.
- Add a custom column. Go to Add Column > Custom Column. In the formula box, you will call Record.AddField. The syntax is
Record.AddField(record as record, field as text, value as any, optional delayed as nullable logical) as record. The first argument is the record, the second is the new field name as text, the third is the value to assign. - Write the expression. For example, if your record column is named
RecordColumnand you want to add a field calledStatuswith the value "Active", enter:Record.AddField([RecordColumn], "Status", "Active"). If the value should come from another column, replace "Active" with[OtherColumn]. - Handle errors. If the record column can be null, wrap the call in
try ... otherwise. For example:try Record.AddField([RecordColumn], "Status", "Active") otherwise null. This prevents the whole column from failing when a record is missing. - Expand the new record. After adding the custom column, you will see a new column of records. Click the expand icon (double arrow) in the column header and choose the fields you want to surface, including the new one. This converts the record back into visible columns.
- Check the result and rename. Review the expanded columns and rename them if needed (right-click the column header > Rename). Then close and load the query.
Common Mistakes
- Passing a table instead of a record. Record.AddField expects a single record, not a table. If you have a table, use Table.AddColumn with a record expression, or transform each row first.
- Forgetting to expand. The function returns a record, so the new field is not visible until you expand the record column. Many users think the step failed because they only see a record value.
- Using a non-text field name. The second argument must be text. If you pass a number or a field reference without quotes, you will get an error.
- Ignoring nulls. If any record is null, the function errors. Always guard with try/otherwise or filter out nulls first.
- Overwriting an existing field. Record.AddField will replace the value if the field already exists. Check the record's fields first to avoid losing data.
Tips
- Use the formula bar to edit the step after creation; it is often faster than reopening the Custom Column dialog.
- To add multiple fields, nest calls:
Record.AddField(Record.AddField([RecordColumn], "A", 1), "B", 2). - If you need to add a field only when a condition is met, combine with
if ... then ... elseinside the custom column. - Keep field names consistent with your downstream schema; Power Query is case-sensitive for field names.
- Use
Record.FieldNamesto list existing fields before adding, which helps avoid duplicates.
Troubleshooting
If you see "Expression.Error: We cannot convert a value of type Table to type Record", you passed a table. Check the column type: select the column and look at the icon in the header; a record column shows a record icon. If the error is "We cannot convert null to type Record", add a null check. If the new field does not appear after expanding, ensure you selected it in the expand dialog; sometimes the expand step caches the old field list, so delete and re-add the expand step. If the query is slow, avoid adding fields inside a large table without filtering first; record operations are row-by-row and can be expensive. If the field name contains spaces or special characters, wrap it in quotes and use the exact text, including case.
Frequently Asked Questions
Can I add a field to a record in a table column?
Yes, use Add Column > Custom Column with Record.AddField referencing the record column, then expand the resulting record column.
What happens if the field already exists?
Record.AddField overwrites the existing value with the new one. To avoid this, check with Record.HasFields first.
Does Record.AddField work in Power BI Service?
Yes, it works in Dataflows and datasets that use Power Query, as long as the M engine supports it (it does in current versions).
How do I add a field with a dynamic name?
Pass a text expression as the second argument, for example Record.AddField([RecordColumn], [FieldNameColumn], [ValueColumn]).
Can I use Record.AddField on a null record?
No, it errors. Wrap the call in try ... otherwise to return null or a default record.
Is there a limit to how many fields I can add?
No hard limit, but each nested call adds overhead. For many fields, consider building a record with Record.FromList instead.