You are currently viewing Canvas App Collections

Canvas App Collections

in this article we will discuss every operation we can perform with PowerApps canvas app collections.

What are Canvas App collections?

  • Collections in the Canvas App are considered a type of data source that stores data locally in the app.
  • Collections are multi-row valued variables used to store tables.
  • The scope of collections in PowerApps is within the app.
  • It can be saved to the local device for later use.
  • A collection may be generated using the values from a SharePoint List, an Excel Sheet, SQL, Dataverse, or any other data source.
  • Collections exist only when an app is active. When an app is ended, the data contained in a collection is erased.
  • A collection may be used as the data source for galleries, forms, and data tables.
  • Because data is saved on the local device rather than on the cloud, using collections as a data source helps minimize loading times.
  • Once established, a collection may be accessed from any screen.
  • Once a collection is created, all powerapps functions can be delegated to the collection including Search() and all numeric functions.

Canvas App create Collection

You can initialize a collection by using the ClearCollect() function.

ClearCollect(CollectionCol, {UserName: "ABC", email:"abc@gmail.com"})

ClearCollect() clear the entire content of the collection if it already exists

You can create the collection also from a data source for example from a SharePoint list as following

ClearCollect(CollectionName, SharePointList)

Collect() and ClearCollect() are not delegatable so they max out at 2000 items

you will find all collections used within your Power App and their contents, you can go to File > Collections.

Canvas App Collection
Canvas App Collection

Collect and Clearcollect in PowerApps

  • Collect function
    • The Collect function in PowerApps is used to create the collections that will hold our required data.
    • The Collect function adds records to a data source.
  • ClearCollect function
    • The PowerApps ClearCollect method, on the other hand, is used to delete an item from a collection and add a new item to the same PowerApps Collections.

Canvas App Clear Collection

The Clear function deletes all the records of a collection, Clear has no return value. It can only be used in a behavior formula.

Syntax

Clear( Collection )

The collection that you want to clear.

Canvas App Delete Collection

If you don’t want the collection created anymore, and as we know that the collection only shows up there when it is created through a formula in your app. So locate the formula that creates your collection and delete the collection function that creates it.

Canvas App Collection Count

You can use the PowerApps Count function that helps you to count all records in a table. Also, besides counting all items that satisfy a condition.

Syntax

Count (SingleColumnTable)
CountRows(Mycollection)

SingleColumnTable here will be your collection name.

  • If you want to count the number of items that are not blank in a table you can use the CountA function

Syntax

CountA( SingleColumnTable )
  • If you want to count the number of records accourding to a condition you can use the CountIf function.

Syntax

CountIf( Table, LogicalFormula )

 Records that return true for this formula are counted.

  • You can get a Sum of a column in the collection using this formula
Sum(Mycollection,columnName)
  • You can get the average of a column using this formula
Average(Mycollection,columnName)
  • You can get the Max value of a column using this formula
Max(Mycollection,columnName)
  • You can get the MIn value of a column using this formula

Min(Mycollection,columnName)

Canvas App Collection to string

You can use the string concatenate function that is used to join two or more strings.

Syntax

Concat( Table, Formula, separator)

we plan to store data from the table or collection into a single column in SharePoint or SQL Database, then we use the Concat() function.

Canvas App sort Collection

You can use the Sort function to sort a table based on a formula.

Syntax

Sort( Table, Formula [, SortOrder ] )
Sort( Products, Quantity )

You can apply for the sort order as shown below,

Sort( Products, Quantity, SortOrder.Descending )

Canvas App remove Collection Item

you can use the

Syntax

Remove( DataSource, Record1 [, Record2, ... ] [, All ] )

Record(s) – Required. The record or records to remove.

Remove(ProductList, ThisItem)

you can check this video for learning how to work with collections as a kind of data source.

Conclusion

Collections in the Canvas App are considered a type of data source that stores data locally in the app.

SeeAlso

Heba Kamal

Microsoft MVP, MCT, Technical Speaker, Blogger, and Microsoft 365 and Power Platform Consultant.