Blog

Data - How to remove/delete a field from a record

From time to time, it may be necessary to remove or delete one or more fields from a single record. This post describes the formula to carry out this task.

When we work with data, there can sometimes be the requirement to delete or remove fields from a record.

An example of where this can happen is in situations where we define a record that may contain 'working fields' to support the operation of an app. This could include temporary sequence number, or fields to support the appearance or presentation in the app.

At the point at which we want to save the record to a data source, there may be the requirement to remove these extraneous fields so that we can pass the record to the Patch function.

When we work with tables of data, we can call the DropColumns function to drop columns from the table. When we work with a single record however, there's no equivalent function to drop fields from an individual record.

To work around this limitation, one technique is to create a single row table that contains the record without the unnecessary columns and to extract the first record from this table.

Demonstration - How to remove fields from a record

As an example, let's take the following formula that defines a record and stores it in a variable called varRecord.

Set(varRecord,
{
Forename:"Tim",
Surname:"Leung",
Address:"10 Kings Road",
City:"London",
UpdateDatabase:true,
SequenceNo:5
}
)
The definition of this record contains two fields for use in our app - UpdateDatabase and SequenceNo.To return the record without these two fields, we would use the following syntax.

First(
DropColumns(Table(varRecord),
"UpdateDatabase",
"SequenceNo"
)
)
We can then use this syntax to patch the record (without these two fields) to a data source. The syntax would look like this:

Patch(CustomerList,
Defaults(CustomerList),
First(
DropColumns(Table(varRecord),
"UpdateDatabase",
"SequenceNo"
)
)

Conclusion

With Power Apps, there's no "DeleteFields" function to delete or remove fields from a single record. However, we can work around this limitation by transforming the record into a table, dropping the columns, and returning the first record from this table.