Record.AddField Function in Power Query
The Record.AddField function adds a field in the given record. The field name and its value are given in the function itself.
Syntax
Record.AddField( record as record, fieldName as text, value as any, optional delayed as nullable logical ) as record
The function has the following parameters:
- record: The original record to which the field will be added.
- fieldName: The name of the new field (as text).
- fieldValue: The value that will be assigned to the new field.
Note: If the field which we are adding in the record already exists in the record, then it throws an error.
Example: Add the Salary field to the record.
Power Query M
// Begin the 'let' block to define transformation steps let // Step 1: Create an initial record with four fields // Fields: CustomerID, Name, Phone, and Company Source = Record.AddField( [CustomerID = 1, Name = "Ashish", Phone = "123-4567", Company = "TCS"], // Step 2: Add a new field to this record // Field name: "Salary", Field value: 70000 "Salary", 70000 ) // Final output: the updated record with the additional "Salary" field in Source
The output of the above code is shown below:
