Blog

Data - How to rename field names in a record

From time to time, it may be necessary to rename a field name in a record. This post describes the formula to carry out this task.

When we work with data, there can sometimes be the requirement to rename field names in the record.

An example of where this can happen is in situations where we want to retrieve a record from one data source and to patch it into another data source. With this use case scenario, it may be necessary to rename the field names of the source record so that they match the field names in the target data source.

When we work with tables of data, we can call the RenameColumns function to rename the column of the table. When we work with a single record however, there's no equivalent function to rename the field name of an individual record.

To work around this limitation, one technique is to create a single row table that contains the record, rename the column, and to extract the record withe the renamed column.

Demonstration of how to rename a record field name

As an example, let's take the following formula that defines a record and stores it in a variable called varRecord. In practice, we could retrieve this record from a data source, Flow, or a custom connector.

Set(varRecord,
{
Forename:"Tim",
Surname:"Leung",
Address:"10 Kings Road",
City:"London"
}
)
Here's how the record looks in the designer.


Let's now suppose that we want to rename Forename to Firstname, and Surname to Lastname. The formula to carry out this task would look like this:

First(
RenameColumns(Table(varRecord),
"Forename",
"Firstname",
"Surname",
"Lastname"
)
)

Here's the formula to store this record in a variable called varRecordNew:
Set(varRecordNew,
First(
RenameColumns(Table(varRecord),
"Forename",
"Firstname",
"Surname",
"Lastname"
)
)
)
Finally, here's how this new record looks in the designer:

Conclusion

With Power Apps, there's no "RenameFields" to rename the fields of a single record. However we can work around this limitation by transforming the record into a table and calling the RenameColumns function.
  •   Categories: 
  • data
Related posts