Blog
Data - How to rename field names in a record
July 14. 2021
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.
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
Set(varRecord,Here's how the record looks in the designer.
{
Forename:"Tim",
Surname:"Leung",
Address:"10 Kings Road",
City:"London"
}
)
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
- Data - How to find the common rows from 3 or more collections
- Data - How to show the distinct rows from 2 data sources or collections
- Data - How to implement circular rotational date sorting
- Bug - What to do when the data section of the Power Apps Maker portal doesn't work
- Data - Combine columns from separate tables into a single table
- Formula - Transposing/converting rows to columns- an almost impossible task?
- Data - How to hide duplicate rows in a gallery / show distinct multiple columns in a gallery
- Data - Retrieving news/forum/blog articles with RSS
- Data - How to sort by partial numbers in a text field
- Data - How to return the last record from a table
- Data - How to create bulk test/dummy records with random values
- Data - 3 things you should know before using the MySQL or PostgreSQL connectors
- Data - A walkthrough of how to migrate the data source of an app from Excel to Sharepoint
- Data - How to enforce unique values (or prevent duplicate values) in one or more columns
- Data - How much mobile data does Power Apps consume? What ways can we minimise this?
- Data - How to save and retrieve Google calendar entries
- Data - How to save and retrieve Google contacts
- SQL - Caution! This is how users can hack shared SQL connections
- SharePoint – 2 Mistakes to avoid when importing Excel data
- SQL - Don't let this DateTime bug catch you out!
- Settings - What's the purpose of the "Explicit Column Selection" Setting?
- SQL Server for Beginners Part 3 - Installing On-Premises Gateway
- SQL Server for Beginners Part 2 - Installing Management Studio
- SQL Server for Beginners Part 1 - Installing SQL Server
- Searching data–What you need to know about case sensitivity
- Images - How to create images that can change depending on data
- Excel - Reasons NOT to use Excel as a data source
- SharePoint - What you need to know about Filtering Data
- Formulas - Generating Row Numbers