How to use collections in PowerApps


Posted By : Rakesh Pandey

Added :

1 Comment


How to use collections in PowerApps ?

Hello Everyone !! As promised in my last blog, today we will discuss How to use collections in PowerApps with examples. Most of the PowerApps applications uses collect function to work with collections.

Collect Function

As per Microsoft definition: The Collect function adds records to a data source. Similarly like collecting list items temporarily in a Table. And further we can use this table or datasource in our applications.

How to use it ?

Syntax for the Collect function is given below.

CollectDataSourceItem, … )

  • DataSource – Required. The data source that you want to add data to. If it does not already exist, a new collection is created.
  • Item(s) – Required. One or more records or tables to add to the data source.

eg.
Collect( Car, { Brand: “Ford”, Colour: “Red” }, { Brand: “Toyota”, Colour: “Black” } )

Figure 1.

Collections are sometimes used to hold global variables or make a temporary copy of a data source.

For more details on Collect please refer link.

Example:

We have already seen the basic concepts and syntax of Collect function. Now you will see the implementation of collection with an example. In below figure you can see that we have created a simple screen with a gallery, textboxes and buttons.

Figure 2.

In above example we will collect the Name and Phone Number items into a gallery. In order to do this we have written below code on OnSelect event of “Add to Collection” button

Collect(EmployeeList,{Name:TextInput1.Text,Phone:TextInput2.Text})

Now bind the items of EmployeeList collection with the gallery. Use Items = EmployeeList to bind the items.

Once you are done with above steps run the application to see the results like below.

Figure 3.

“Clear Collection” button will clear the whole “EmployeeList” collection. OnSelect event on this button is Clear(EmployeeList).

Delete Icon in the gallery will delete the current item from it. Basically Remove function will remove a specific record or records from a data source.

Here we are using Remove(EmployeeList,ThisItem) delete icon to remove the current item from the gallery.

If you want to verify your collections, goto File -> Collections -> <EmployeeList/your collection name>

Figure 4.

Hope you like this blog, subscribe our site for more stuff on powerapps, flow, azure and other cloud technologies. Very soon we are going to publish quizzes on Azure, PowerApps and Flow on our site under the quiz section, please go through that quizzes to test your knowledge !!

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Hamid
Hamid
3 years ago

Hi
Thanks for your instruction. I followed it and works fine. However, I have a question. How can I clear the input fields (Name and Tel number” after selecting “Add to Collection”. Currently, the last inserted value remains