Power Apps Collection [Complete Guide]

This Power Apps tutorial will walk you through several examples of how to use the collection in Power Apps based on various scenarios.

We recently stuck on using the collection in various situations while working with the Power Apps canvas apps.

It will also be covered how to use the Power Apps collection with the items listed:

  • What is the Power Apps collection?
  • What is the syntax of the Power Apps collection?
  • How to make a collection within the Power Apps?
  • How to show a Power Apps collection?
  • How to build a Power Apps collection with multiple columns?
  • What are the limits of the Power Apps collection?
  • How to build a Power Apps collection on button selection?
  • How to get the length of a Power Apps collection?
  • How to build a Power Apps collection OnStart?
  • How to build a Power Apps dynamic collection?
  • How to work with the Power Apps collection ClearCollect()?
  • How to get the PowerApps collection’s first value?
  • How to get the Power Apps collection’s last value?
  • How to rename a column in a Power Apps collection?
  • How to rename all columns in a Power Apps collection?

What is the Power Apps Collection?

A collection is like a table of values. A Power Apps Collection is an array that aids in storing data in PowerApps memory, which can then be used in various ways.

It enables the data in a PowerApps Collection to be saved to any data source, such as a SharePoint Online List, an Excel spreadsheet, or a database.

Make sure to keep the column’s values all of the same type (for example, text, number, date, or true or false).

A collection can be formed from the values of a SharePoint List, an Excel Spreadsheet, SQL, CDS, or any other data source.

We can use a collection as the data source for Galleries, Forms, and Data Tables.

What is the syntax of the Power Apps collection?

To create a PowerApps Collection, use the following syntax:

Collect(collection, item, ...)

Where,

  1. Collect: This function allows to add the records to a data source.
  2. collection: Specify the new or existing collection name to augment
  3. item(s): collect a record or table. A new entry will be added to the collection. The rows of a table will be appended to the collection.

Also Read: Power Apps Timer Control Examples

Create a Power Apps Collection

Now we’ll look at how to create a collection in Power Apps. Let’s make a collection based on the screen’s visible time so that when we open the screen, the specific collection will be created within Power Apps, and the steps are as follows:

  • Add a blank screen to the Power Apps canvas app.
  • Insert the below expression on the screen’s OnVisible property to create the collection.
OnVisible = Collect(CollProduct, {Product: "Laptop" })

Where,

  1. CollProduct: The new collection’s name.
  2. {Product: “Laptop”}: The record. Where the Product is the name of the collection’s header or column, and Laptop is the name of the value.
Create a collection in Power Apps
Create a collection in Power Apps

This is how to create a simple collection on the Power Apps screen’s visible property.

Check Out: Power Apps Notify() function [How to use with examples]

Show Power Apps collection

Sometimes we wonder where we put the collection we made. Within the Power Apps, there is a separate section for displaying the collection and its associated values.

We can find the collection, through the following steps are:

Click the Ellipses (…) on the top tab of the Power Apps screen > Select Collections.

Show PowerApps collection
Show PowerApps collection

Then it will redirect to the page where we can find the collection table with values shown below:

Display Power Apps collection
Display Power Apps collection

Also, we can show this collection’s data on the Power Apps screen via the gallery, and data table. For this, the following steps are:

  • Let’s add a Power Apps data table to the screen.
  • Connect that collection to the data table as a data source.
  • Add the field to the data table.
Show collection in Power Apps
Show collection in Power Apps

This is how to show the collection in the Power Apps.

Have a look: Power Apps Filter With Date Picker

How to build a Power Apps collection with multiple columns?

Similarly, here we will see how to create a Power Apps collection with multiple columns. On that collection, we will add multiple columns having different values.

Insert the below expression on the Power Apps screen’s OnVisible property:

OnVisible = Collect(CollProduct, {Product: "Laptop", Manufacture: "Dell", Quantity: 12}, {Product: "Mouse", Manufacture: "Hp", Quantity: 15}, {Product: "Tablet", Manufacture: "Samsung", Quantity: 08}, {Product: "Laptop", Manufacture: "Apple", Quantity: 22}, {Product: "Mobile", Manufacture: "Apple", Quantity: 35})

Where,

  • CollProduct: The name of the collection
  • Product, Manufacture, Quantity: The name of the collection’s columns.
Power Apps collection with multiple columns
Power Apps collection with multiple columns

That’s it. Whenever we open the screen, the collection and the values will be displayed in the Power Apps collection section or we can display them via a data table shown below:

Build Power Apps collection with multiple columns
Build a Power Apps collection with multiple columns

This is how to build a Power Apps collection with multiple columns.

What are the limits of the Power Apps collection?

  • There is a limitation on the number of items in each data source in Powerapps (for example, SharePoint, OneDrive, the Common Data Service, and so on).
  • It allows us to add 500 items from a data source at a time. If we add more than 500, the PowerApps will not allow you to do so.
  • Collections exist only while an app is running. When an app is closed, the data stored in a collection is erased.

How to build a Power Apps collection on button selection?

In this section, we will see how to create a Power Apps collection on select, i.e., the button on select. That means we will be configuring a button control with a collection expression. As result, when the user clicks on the button, it will create a collection within the Power Apps.

For this the following steps are:

  • Add a button control to the Power Apps screen.
  • Rename the button as Create Collection.
  • Insert the below expression on the button’s OnSelect property.
OnSelect = Collect(ColCapital,{Country: "USA", Captial: "WASHINGTON"}, {Country: "UNITED KINGDOM", Captial: "LONDON"}, {Country: "VIETNAM", Captial: "HANOI"}, {Country: "THAILAND", Captial: "BANGKOK"}, {Country: "SPAIN", Captial: "MADRID"}, {Country: "RUSSIA", Captial: "MOSCOW"}, {Country: "UKRAINE", Captial: "KIEV"} )

Where,

  1. ColCapital: The name of the new collection
  2. Country, Captial: The name of the collection’s columns
Power Apps collection on select
Power Apps collection on select

That’s it. Let’s preview the app and click on the button control. Once we select the button, the collection will create on the Power App.

PowerApps collection on select
PowerApps collection on select

The above preview of the collection is displaying the first 5 items. But we can display all the items via a gallery or data tables using the collection data source.

Suppose, we will use a vertical gallery to display all the records of the Power Apps collection.

Create Power Apps collection On Select
Create Power Apps collection On Select

This is how to create a Power Apps collection On Select.

Read Post: How To Set Default Date in Power Apps Date Picker

Power Apps collection get length

We’ll look at how to get the length of the Power Apps collection in this section.

Assumes, we are going to use the above existing collection i.e., ColCapital. Now we’ll look at how to get the total number of items in the Power Apps collection.

To get the length of the Power Apps collection, the following steps are:

  • On the above Power Apps screen, add a text label control.
  • Insert the below expression on the label’s Text property.
Text = "The Total No. of Items is: " & CountRows(ColCapital)

We can see the total count or length of the collection on the label control shown below:

Power Apps collection get length
Power Apps collection get length

This is how to get the total length of the Power Apps collection.

Power Apps collection onstart

Here, we will see how to work with the Power Apps collection OnStart. This means that a collection will be created while the app is being launched.

For this, the following steps are:

  • Open a Power Apps canvas app.
  • On the canvas app, insert the below expression on the OnStart property of the Apps to build a collection.
OnStart = Collect(ColBook, {Name: "The Great Gatsby", Author: "F. Scott Fitzgerald"},{Name: "Of Mice and Men", Author: "John Steinbeck"},{Name: "Little Women", Author: "Louisa May Alcott"}, {Name: "Catch-22", Author:"Joseph Heller"})
Power Apps collection onstart
Power Apps collection onstart

Let us examine the collection. As shown below, the collection is formed without records:

PowerApps collection onstart
PowerApps collection onstart

Now, save, publish, and close the app. When we reopen the app, we can see the collection is built having all the records shown below:

Build PowerApps collection onstart
Build PowerApps collection onstart

This is how to build a PowerApps collection at the app’s start.

Read: How to disable Power Apps date picker

Power Apps Dynamic Collection

Here, we will see how to build a dynamic collection within the Power Apps. Instead of building a collection manually, we will see how to create a Power Apps collection dynamically.

Assume we’re going to make a collection with columns like Task Name, Start Date, and Technology. The user will dynamically insert all of the data from the various Power Apps controls into the collection.

For this, the following steps are:

Items = ["Microsoft Power Platform", "Python", "Java"]
Power Apps dynamic collection
Power Apps dynamic collection
  • Insert a button control into the screen and set the text property as Save.
  • Configure the below expression in the OnSelect property.
OnSelect = Collect(ColTask, {Task: Task_Txt.Text, StartDate: StartDate_DatePicker.SelectedDate, Technology: Technology_dd.Selected.Value})

Where,

  1. ColTask: The name of the collection
  2. Task, StartDate, Technology: The columns of the collection
  3. Task_Txt, StartDate_DatePicker, Technology_dd: The name of the text input, date picker control, and drop-down control respectively.
Build a Power Apps dynamic collection
Build a Power Apps dynamic collection
  • When the user clicks the button it will store in the collection and display via a vertical gallery.
  • For this, add a Power Apps vertical gallery and set the data source as the collection name i.e., ColTask.
PowerApps dynamic collection
PowerApps dynamic collection

Let’s preview the app. Insert all the information on the Power Apps control and click on save. We can see the collection with the information will reflect in the vertical gallery shown below:

Build PowerApps dynamic collection
Build PowerApps dynamic collection

This is how to build a dynamic collection within the Power Apps.

Power Apps collection clearcollect

Previously, we discussed what a Power Apps collection is and how to create a collection to store data. However, we may be wondering what clearcollect is in the Power Apps collection and how we can use it to build a collection.

To answer this question, here we are going to discuss the clearcollect method in Power Apps and also see how to use this method to build a collection.

In Power Apps, the ClearCollect() deletes all of the records in a collection. Then it adds another set of records to the same collection. ClearCollect provides the combination of Clear and Collect in a single function.

ClearCollect returns the modified collection in the form of a table. ClearCollect can only be found in behavior formulas.

Let’s take the example of creating a collection using the ClearCollect function within Power Apps. For this, we are going to use the above example of dynamic collection, and the following steps are:

  • Insert the below expression on the Save button’s OnSelect property.
OnSelect = ClearCollect(ColTaskDetails, {Task: Task_Txt.Text, StartDate: StartDate_DatePicker.SelectedDate, Technology: Technology_dd.Selected.Value})

Where ColTaskDetails is the name of the collection.

Power Apps collection clearcollect
Power Apps collection clearcollect
  • Also, set the collection name i.e., ColTaskDetails as the data source of the vertical gallery.
  • Now, preview the app and fill in the control. Click on the Save button. We can see the collected data will display in the gallery.
PowerApps collection clearcollect
PowerApps collection clearcollect
  • Again, fill in the Power Apps controls and click on the save button. We can see the previous record has now been deleted, and the new record has been added to both the Gallery control and the PowerApps Collections.
How to Create ClearCollect in PowerApps
How to Create ClearCollect in PowerApps

This is how to work with the ClearCollect function to build a collection in the Power Apps.

Look: How to Patch Power Apps Date Picker

How to get the PowerApps collection’s first value?

In this section, we will see how to display the first value of the Power Apps collection.

That means we will build a collection on the button click and extract the first row of that collection within the Power Apps. To work with this requirement, the following steps are needed:

  • On the Power Apps screen, add a button control and insert the below expression on the OnSelect property to create a collection.
OnSelect = Collect(CollProduct, {Product: "Laptop", Manufacture: "Apple", Quantity: 252}, {Product: "Mouse", Manufacture: "Dell", Quantity: 115}, {Product: "Tablet", Manufacture: "Samsung", Quantity: 78}, {Product: "Desktop", Manufacture: "Lenovo", Quantity: 110}, {Product: "Mobile", Manufacture: "Apple", Quantity: 35});
  • Add a data table to the screen and set the collection name (i.e., CollProduct) as the data source.
  • Press the Create collection button while clicking on the Alt key to create the collection.
PowerApps collection first value
PowerApps collection first value
  • Next, as we want to extract the first row of the above collection insert another button on the screen. Set the text as “First Value of collection“.
  • Insert the below expression on the button’s OnSelect property.
OnSelect = ClearCollect(ColFirstProduct, First(CollProduct));

Where ColFirstProduct is the name of the new collection and CollProduct is the name of the previously created collection.

Power Apps collection first row
Power Apps collection first row
  • Similarly, add a data table and set the Items as a new collection i.e., ColFirstProduct.
  • Once we click on the button, the first row of the above collection will be visible in the second data table shown below:
Power Apps collection get first value
Power Apps collection get first value

This is how to get the first value from the Power Apps collection.

Check post: How to Reset Power Apps Date Picker

Power Apps collection last value

Unlike getting the first value of the Power Apps collection, in this section, we will see how to get the last value or last row of the Power Apps collection.

The following steps are required for this:

  • Insert another button control to the screen and set the text as Last Value of Collection.
  • Insert the below expression on the button’s OnSelect property to extract the last value from the existing collection i.e., CollProduct.
OnSelect = ClearCollect(ColLastProduct, Last(CollProduct));

Where ColLastProduct is the name of the new collection to store the last value.

  • Add a data table to the screen and set the Items as ColLastProduct to display the last row of the collection.
  • Once the button is clicked the item will display within the data table shown below:
Power Apps collection last value
Power Apps collection last value

This is how to get the last row of the Power Apps collection.

Read: [Solved]Can’t convert this data type. Power Apps can’t convert this Date to a Boolean

Power Apps rename a collection column

Now, we will see how to rename a column within the Power Apps collection. Assumes we are going to use the above collection i.e., CollProduct. Under that collection, we will rename the column name from Product to Device.

The following steps are required for this:

  • Add a button to the Power Apps screen. Set the text to Rename Column.
  • On the button’s OnSelect property, enter the expression shown below. As a result, when the user clicks the button, it displays all of the items from the existing collection while renaming the column.
OnSelect = ClearCollect(NewCollProduct, RenameColumns(CollProduct, "Product", "Device"))

Where,

  1. NewCollProduct: The name of the new collection
  2. CollProduct: The name of the existing or source collection
  3. Product“: The existing column name or old name of the column
  4. Device“: The new name of the column.
Power Apps rename collection column
Power Apps rename collection column
  • To connect with the new collection, add a data table to the screen and set the Items to NewCollProduct.
  • When we click the button, we can see that it will rename the collection’s column and display all the items from the existing collection.
Power Apps rename the collection column
Power Apps rename the collection column

This is how to rename a collection column within the Power Apps.

Check: Power Apps Checkbox control within Gallery

How to rename all columns in a Power Apps collection?

Similarly, we’ll look at how to rename all of the columns in an existing collection. Suppose, we want to rename the column name from Product to Goods, Manufacture to Brand, Quantity to Units in the CollProduct collection.

The following steps are required for this:

  • Add a button control to the Power Apps screen.
  • Set the Text as Rename all columns.
  • Insert the below expression on the Power Apps button’s OnSelect property.
OnSelect = ClearCollect(NewProductCollection, RenameColumns(CollProduct, "Product","Goods","Manufacture","Brand","Quantity","Units"))

Where,

  • NewProductCollection: The name of the new collection
  • CollProduct: The name of the existing collection.
  • Product“, “Manufacture“, “Quantity“: The old name of the columns
  • Goods“, “Brand“, “Units“: The new name of the columns.
Power Apps collection rename all columns
Power Apps collection rename all columns
  • Add a data table to the screen and set the Items as NewProductCollection to display the collection.
  • Once the button is clicked, we can see all the values with new column names on the data table.
Rename all columns in Power Apps collection
Rename all columns in Power Apps collection

This is how to rename all the columns in the Power Apps collection.

Furthermore, you may like some more Power Apps tutorials:

Conclusion

This Power Apps Tutorial taught us everything we know about the Power Apps collection and how to use it with the Power Apps in various situations, such as:

  • Power Apps collection
  • Power Apps collection syntax
  • Make a collection in Power Apps
  • Show Power Apps collection
  • Power Apps collection with multiple columns
  • Power Apps collection limit
  • Power Apps collection on select
  • Power Apps collection gets the length
  • Power Apps collection onstart
  • Power Apps dynamic collection
  • Power Apps collection clearcollect
  • PowerApps collection first value
  • Power Apps collection’s last value
  • Power Apps rename collection column
  • Power Apps collection renames all columns
>