RenameColumns functions in Power Apps
The AddColumns, DropColumns, RenameColumns, and ShowColumns functions in Power Apps are used to shape the table by adding, dropping, renaming, and selecting its columns. All these functions, results in a new table, but note that the original table that is our data source is not modified at all by these functions.
RenameColumns Function
The RenameColumns function is used to manipulate the name of the column within our app but not within our data source. A common use is when the data source, which we cannot edit, has difficult to reference column name or the column name uses reserved words, like "Date".
Power Apps Syntax RenameColumns(Table, OldColumnName1, NewColumnName1 [, OldColumnName2, NewColumnName2, ... ] )
- Table – It is a required parameter. It specifies the tabular data source to operate on.
- OldColumnName – It is a required parameter. It specifies the name of a column to rename from the original table. This element appears first in the argument pair (or first in each argument pair if the formula includes more than one pair).
- NewColumnName - It is a required parameter. The new name of the column. This element appears last in the argument pair (or last in each argument pair if the formula includes more than one pair).
Note: The column name should be in single quotes if the column name has space in its name otherwise, we can omit the single quotes (for example, Name and ‘Total Marks’).
The old name must already exist in the table, and the new name must not exist. Each column name may appear only once in the argument list as either an old column name or a new column name. To rename a column to an existing column name, first drop the existing column with DropColumns, or rename the existing column out of the way by nesting one RenameColumns function within another.
Note that the Collect function can take the contents of your data source and store them into a collection.
Power Apps Formula
The above formula will create a collection variable named MyRenameCollection that stores all the rows of data from the data source, 'Teachers Data'. If the data source has a column named 'Teacher salary', the column is renamed to Salary.
Set the Items property to the collection variable MyRenameCollection.
The third label is used to specify the Salary. Set the Text property to the formula ThisItem.Salary.