Power Apps collections are a powerful feature that allow you to store and manipulate data in-memory within your app. Whether you’re building a prototype or managing temporary data, collections give you flexibility without needing a backend database. In this tutorial, you’ll learn how to use three essential functions: Collect
, Clear
, and ClearCollect
.
What Is a Collection in Power Apps?
A collection is an in-memory data table that stores records temporarily while your app is running. Think of it like a spreadsheet that lives inside your app—it can hold multiple rows and columns, and you can add, remove, or update data dynamically.
Setting Up the UI
To demonstrate collections, we’ll build a simple app that stores U.S. cities and their corresponding regions.
Controls Used:
- Text Label: Displays static text like “USA Regions”
- Text Input: Allows users to enter a city name
- Radio Control: Lets users select a region (e.g., West, Midwest)
- Button: Triggers actions like adding to or clearing the collection
- Data Table / Gallery: Displays the contents of the collection
Using the Collect
Function
The Collect
function adds new records to a collection.
Collect(
CollectionCities,
{ City: TextInput1.Text, Region: Radio2.Selected.Value }
)
This function is triggered when the “Add to Collection” button is clicked.
Displaying the Collection
To visualize the data:
- Insert a Data Table or Gallery
- Set its
Items
property toCollectionCities
- Choose the fields to display:
City
andRegion
Using the Clear
Function
The Clear
function removes all records from a collection.
Clear(CollectionCities)
This is used in the “Clear” button to reset the collection.
Using the ClearCollect
Function
ClearCollect
combines both clearing and adding in one step. It first clears the collection, then adds a new record.
ClearCollect(
CollectionCities,
{ City: TextInput1.Text, Region: Radio2.Selected.Value }
)
This is ideal for scenarios where you want to replace the existing data with a new entry.
Summary of Power Apps Collections Functions
Function | Purpose |
---|---|
Collect | Adds a new record to the collection |
Clear | Removes all records from the collection |
ClearCollect | Clears the collection and adds a new record |
Power Apps collections are incredibly useful for managing temporary data. Whether you’re building a form, a dynamic list, or a prototype, mastering these three functions—Collect
, Clear
, and ClearCollect
—will give you the control you need.
Leave a Comment