In this blog, we will show what is Collect, Clear and ClearCollect functions in Power Apps
Collect
- Records are added to a data source using the Collect function. The additional items could be:
- An individual value: The value is entered into a new record’s Value field. The remaining properties are all left empty.
- The matching property of a new record is where each named property is put. The remaining properties are all left empty.
- As mentioned before, each record in the table is added as a separate record to the data source. The table is not added to a record as a nested table. Wrap the table in a record first before doing this.
- More columns will be added when used with a collection. New columns cannot be added because the columns for other data sources are determined by the data source.
- A collection is generated if the data source doesn’t already exist.
- Moreover, you can add records to a data source by using the Patch function.
- The changed data source is returned by Collect as a table. The only way to utilize collect is in a behavior formula.
Clear
- A collection’s entire record set is deleted using the Clear function. The collection’s columns will remain.
- Keep in mind that Clear does not operate on other data sources, just collections. For this, you can use RemoveIf(DataSource, true). Take care because this can have an impact on other users and will delete all of the records from the data source’s storage.
- To remove specific records, utilise the Remove function.
- Clear provides no useful return. Only a behaviour formula can use it.
ClearCollect
- All of the records in a collection are removed using the ClearCollect function. and after that updates the same collection with a new batch of records. ClearCollect combines the functions of Clear and Collect into a single function.
- The changed collection is returned by ClearCollect as a table. The only way to utilise ClearCollect is in a behaviour formula.