Skip to content
Home » Collection in Power Apps

Collection in Power Apps

A collection is used to store and manage a group of items or records. It acts as an in-memory data source.

It allows you to create, modify, and manipulate the data without the need for an external data source. Collections are useful in scenarios where you need to make a temporary copy of a data source.




Creating a collection 

Create a collection to store the employee details such as employee name and department name. Values for employee name and department name will be taken through text input control.

Log into Power Apps portal,  create a blank canvas app as shown below.

Lets add two Text input control one for Employee Name and second for Department Name, go to Insert tab then select Text input control from dropdown list.

Now set the properties for Employee Name Text input control.

Now provide the proper name to this control. Just select the control, click on ellipses and select Rename as shown below.

Similarly, set the property for Department Name Text input control.

Now, add a Button control, go to Insert tab and select Button control from dropdown list as shown below.

Now set its Text property to Add.

Next, we will store the employee details inside the collection through text input controls for this you need to set its OnSelect  property to this formula or code.

Collect (EmployeeDetails, {EmployeeName:txt_empname.Text, DepartmentName: txt_dptname.Text})

Note that, in above formula EmployeeDetails is the name of collection that we want to create,  txt_empname and txt_dptname is the name of Employee Name and Department Name text input controls.

You can, format the code. Just click on Format text button.

Now, click on Preview the app button.

Now, you can see the app preview.




Enter the employee details and click on Add button to store the employee details in collection.

After that, click on Close button to close the Preview mode and check whether the data is getting stored inside the collection or not.

Now, to see the values in collection. Click on Variables button. Then expand the Collections.

Now inside the Collections you can the collection named EmployeeDetails is created.

and it stores the data in form of table. Now, click on Ellipses then click on View table.

Now you can see Employee details is stored inside the collection.

Let’s add one more details inside the collection. Enter the employee details and click on Add button.

You can see, the new record is appended inside the collection.

Show collection data on Gallery Control

You can show the collection data on Gallery control, Go to Insert tab, select Vertical gallery control.

Now, set the gallery’s Items property to EmployeeDetails which is the name of collection or you can simply select the collection in Data Source under Gallery’s properties tab as shown below.

Once you select the data source name you can see the collection data is auto populated in gallery.




Now, now you can set an items properties such as color, font size.

You can see, now gallery look like this after formatting the items color and font size.

Clear all the records from collection

To clear all the records from collection you can use Clear function.

The Clear function deletes all the records of a collection but columns of the collection will remain.

Let’s add one button control, which will clear all the records from collection.

Now, set the button OnSelect  property to code as given below.

Clear(EmployeeDetails);

Lets open the app in preview mode and validate it.

When you click on Clear button, Immediately all the records from collection are removed.

You can see, now there is no items in gallery.

In case, if you want to add new record in collection and delete all existing records from collection then you can use ClearCollect function.

 

Also Read..

Highlight selected item in gallery

Email validation in Power Apps

Sort Items in gallery Power Apps

Change Item color in gallery based on value

 

Loading

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.