Record.RenameFields

This function creates a new record with renamed fields while maintaining the original order. It allows for swapping and chaining field names. However, all new field names, as well as the existing fiel...

Syntax

Record.RenameFields(record as record, renames as list, optional missingField as nullable number) as record

About

This function creates a new record with renamed fields while maintaining the original order. It allows for swapping and chaining field names. However, all new field names, as well as the existing field names, must be unique to avoid errors.

Explanation

Alter the field "UnitPrice" to "Price" in the record using Power Query M. By using the MRecord.RenameFields function, you can change the field name from "UnitPrice" to "Price" in the dataset. For example, if the record includes [OrderID = 1, CustomerID = 1, Item = "Fishing rod", UnitPrice = 100.0], the output will be [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0]. Similarly, you can also modify the fields "UnitPrice" to "Price" and "OrderNum" to "OrderID" in the dataset. By using the MRecord.RenameFields function and specifying the changes as {"UnitPrice", "Price"} and {"OrderNum", "OrderID"}, the output will be [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0].