ClearCollect

ClearCollect

How to Use the Power Fx ClearCollect  Function in Power Apps

What is ClearCollect?

ClearCollect is a Power Fx function used to create a collection from a table or a record. It clears the contents of a collection and then adds the new data to it. The function is used to create collections from data sources and records. With ClearCollect, you can create a collection from static data, dynamic data, or data from SharePoint lists, Excel, and SQL Server databases.

How to Use ClearCollect

To use ClearCollect, you first need to create a collection in Power Apps. You can do this by going to the Insert tab in the Power Apps Studio and selecting Collection. You will then be prompted to name your collection.

Once you have created your collection, you can add data to it using the ClearCollect function. The syntax for the ClearCollect function is as follows:


ClearCollect(collection, data)


In the above syntax, the “collection” parameter is the name of the collection you want to create or add data to, and the “data” parameter is the data you want to add to the collection.

Here’s an example of how ClearCollect can be used:


ClearCollect(MyCollection, { Name: "John Doe", Age: 30, Address: "123 Main St." })


In the above example, we have created a new collection named “MyCollection” and added a record to it with the name “John Doe”, age “30”, and address “123 Main St.”

Adding Data to an Existing Collection

If you want to add data to an existing collection, you can use the same ClearCollect function and simply specify the name of the collection you want to add data to. Here’s an example:


ClearCollect(MyCollection, { Name: "Jane Smith", Age: 25, Address: "456 Elm St." })


In the above example, we have added a record to an existing collection named “MyCollection” with the name “Jane Smith”, age “25”, and address “456 Elm St.”

Clearing the Contents of a Collection

If you want to clear the contents of a collection, you can use the ClearCollect function with an empty table as the data parameter. Here’s an example:


ClearCollect(MyCollection, {})


In the above example, we have cleared the contents of “MyCollection” by passing an empty table as the data parameter.

ClearCollect is a powerful function in Power Apps that can be used to create collections from data sources and records. With ClearCollect, you can add data to a collection, create a new collection, or clear the contents of a collection. We hope this article has helped you understand how to use the ClearCollect function in Power Apps.

Power Apps Training Courses by G Com Solutions (0800 998 9248)