Latest Posts

PowerApps Collections in details


In this article, we are going to learn about collection object in Power apps in details. We will understand how we can create, update the collection how to use them efficiently.

What is Collection in PowerApps?

Definition: Collection in PowerApps is used to collect and store the data so that you can use the data in the app.

  • Collection represents a group of items that are similar like list of items or information about any subject or object.
  • Example of a collection: Here, we have a collection of different items. The collection has got three different properties. This entire set of data table represents one collection.

ItemList

ItemName

ItemType

Manufacturer

Thar

Car

Mahindra

Indica

Car

Tata

Activa

Scooter

Honda

How to create Collection in PowerApps?

  • We will create a similar collection of the table, we mentioned above.
  • Create and open the app in Edit mode.
  • Place three Text boxes and a button control on the screen.
  • Now, we will create collection based on the values added in the textboxes.
  • You can use below syntax to create a collection.
Collect(

ItemList,

{

ItemName: txtItemName.Text,

ItemType: txtItemType.Text,

Manufacturer: txtManufacturer.Text

}

)

  • Keep this formula for OnSelect property of the button.
  • To add one row in the collection you will have to run this command one time. You can repeat this to add multiple rows.

How to view Collections in PowerApps?

  • Click on ellipsis >> Collections.
  • You will see all the collections created here.

How to delete data from the collection?

  • Syntax for clearing the data from the collection is: Clear(<Collection Name>)
  • This will clear all the data from the collection and will return the empty collection.
  • You can put this command on a button’s OnSelect property.

What is ClearCollect used for?

  • The ClearCollect formula deletes all the rows from a collection and then you can add new records in that collection.
  • So, you are clearing the data and adding again in the same collection using single function.
  • Syntax:
ClearCollect(

ItemList,

{

ItemName: txtItemName.Text,

ItemType: txtItemType.Text,

Manufacturer: txtManufacturer.Text

}

)

How to create a collection from a data source?

  • Let’s say you want to create a collection using SharePoint datasource.
  • You can use this simple function.
ClearCollect(ItemList,SharePointDataSource)

How to create multiple rows in a Collection?

  • Single column collection.
ClearCollect(MyNumbers,[1,2,3,4,5])

Output:

Second Example:

Note: You can notice here that the below example contains the header (Day) in the output. Whereas the above example is having the header as (Value) because we haven’t specified the header in there.

ClearCollect(

MyWeek,

{Day: "Monday"},

{Day: "Tuesday"},

{Day: "Wednesday"},

{Day: "Thursday"},

{Day: "Friday"}

)

Output:


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint