Skip to main content

How to Create a Collection in Power Apps with ClearCollect

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

A collection is a table that your app keeps in memory and can change: add rows, remove them, edit them. ClearCollect empties a collection and fills it again in one step, which makes it the usual way to load data into one.

Syntax​

Syntax
ClearCollect( Collection, Item1 [, Item2, ... ] )

ClearCollect deletes all the records in the collection, then adds the items: records, or the rows of a table. If the collection doesn't exist yet, it's created. It works only in behavior properties, such as OnSelect or a screen's OnVisible (Collect, Clear, and ClearCollect functions).

Name collections with the col prefix (Power Apps Naming Conventions).

Example: Load the Competencies for a Job Title​

While building the Career Development Plan app's My Plan screen, the screen's OnVisible first loaded the Sales Engineer competencies into a collection:

My Plan Screen → OnVisible (part of the first version)
ClearCollect(
colMyPlan,
Sort(
Filter(RoleCompetencies, JobTitle = "Sales Engineer" && IsActive = true),
Competency
)
)

OnVisible runs when you go to the screen in preview (How to Run a Formula When a Screen Opens in Power Apps). After that, Variables (the {x} icon on the left) → Collections showed colMyPlan with 2 rows:

The Variables pane with Context variables expanded to My Plan Screen and locIsLoading, and Collections listing colMyPlan with Table: 2 rows and colMyResponses with Table: 0 rows

See What's in It​

Select ... next to the collection → View Table. The two Sales Engineer competencies were there, with every column of the list:

The Variables window with colMyPlan, 2 rows, selected, and a table with the columns Author, Competency, ComplianceAssetId, Created, Editor, ID, IsActive, JobTitle, Level and Modified, showing Customer skill and Leadership, both for Sales Engineer

The Delegation Limit​

ClearCollect itself can't be delegated: Microsoft says only the first portion of a data source is retrieved, up to the app's data row limit (500 by default). Filter first, with conditions SharePoint can run, so that only the rows you need come back. In the example, that's a handful of rows for one job title. See What Is Delegation in Power Apps?

When Not to Use a Collection​

A collection is for data you change in the app, such as a basket of items before you save it. Microsoft's guidance on fast-loading apps says data that's read-only should be used directly, without copying it into a collection (Optimize app or page load).

The App checker agrees. The My Plan screen only read its collections, never changed them, and the checker warned: Collection is initialized but never updated. The finished screen holds the rows in context variables instead.

Common Mistakes​

MistakeWhat happensDo this instead
Collecting a whole large listOnly the first 500 rows (by default) arriveFilter first
Using Clear and then CollectTwo steps for one jobClearCollect
A collection for read-only dataAn App checker performance warningUse the data directly, a named formula or a variable

Troubleshooting​

SymptomLikely causeFix
The collection has 0 rows in StudioThe formula that fills it hasn't runRun it: preview the screen, or Alt+click the button
Rows are missingThe query wasn't delegated, or the data row limit was reachedFix delegation warnings; filter first

FAQ​

ClearCollect or Collect?​

ClearCollect replaces the contents; Collect adds to them.

Where do I see a collection's contents?​

Variables → Collections → ... → View Table.

Conclusion​

ClearCollect(colName, rows) loads rows into a collection, and Variables shows what's in it. Filter first because of the data row limit, and keep collections for data your app actually changes.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.