What is the Collect Function?
The Collect function in Power Fx lets you add a record to a data source. This function is often used when you want to add data to a collection in Power Apps. A collection is a temporary table that stores data in memory for use in the app. Collections can be used to populate galleries, forms, and other controls in Power Apps.
Syntax of the Collect Function
The syntax of the Collect function is as follows:
The Collect function takes two arguments:
How to Use the Collect Function
To use the Collect function in Power Apps, follow these steps:
1. Open the app that you want to modify in Power Apps.
2. Create a new screen or navigate to the existing screen where you want to add the Collect function.
3. Add a button or any other control to the screen and set its OnSelect property to the following formula:
6. Save the formula and test the app.
Adding Multiple Records with Collect
You can also use the Collect function to add multiple records to a data source. To add multiple records, use the following syntax:
In this syntax, the second argument is an array of records that you want to add to the data source.
For example, if you want to add three records to a collection called “MyCollection”, use the following formula:
Using the Collect function in Power Apps is a simple and effective way to add records to a data source. By following the steps outlined in this article, you can add records to a collection or any other data source in just a few clicks. Remember to always test your app thoroughly before deploying it to ensure that it works as expected.