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:

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:

Record.AddField function in Power Query