How to create a collection in Power Apps with ClearCollect
Collections in Power Apps are tables held in the app's memory, used to bring together data from several sources, stage records before saving them, or reduce repeated calls to a data source. Unlike a simple variable, a collection holds many rows at once. Knowing how to create one with ClearCollect is one of the foundations for building fast, well-organized Canvas apps.
Prerequisites
- An account with access to Power Apps (make.powerapps.com).
- A Canvas App open in Power Apps Studio (new or existing).
- Basic familiarity with the formula bar and control properties.
Step 1: Understand what a collection is
A collection is a temporary table that exists only while the app is open: when the user closes the app, the data is gone. It has rows (records) and columns (fields), just like a spreadsheet. The columns are inferred automatically from the first record you insert, so it helps if every record has the same fields. Unlike a variable created with Set, which stores a single value, a collection stores many records — ideal for product lists, cart items, or data the user types in.
Step 2: Create the collection with ClearCollect
The most common way to start is with the ClearCollect function. It does two things at once: it clears the collection (if it already has data) and fills it again, avoiding duplicate records each time the code runs. Add a button to the screen and, in its OnSelect property, write:
ClearCollect(
colProdutos,
{ Produto: "Teclado", Preco: 25, Stock: 10 },
{ Produto: "Rato", Preco: 15, Stock: 20 },
{ Produto: "Monitor", Preco: 120, Stock: 5 }
)Each pair of braces { } represents a record, and each field: value pair is a column. The name colProdutos is up to you, but the col prefix helps you tell collections from variables in the editor. If you want the collection created as soon as the app opens, put the same code in the app's OnStart property or the screen's OnVisible.
Tip: avoid putting ClearCollect inside galleries or in formulas that recalculate often. Call it from a button or at startup so you don't reload the data on every interaction.Step 3: Add records with Collect
To append rows without erasing the existing ones, use Collect. This is what you would do, for example, to save a new product the user typed into text boxes:
Collect(
colProdutos,
{ Produto: txtProduto.Text, Preco: Value(txtPreco.Text), Stock: Value(txtStock.Text) }
)The Value function converts the text from the boxes into a number, so the Preco and Stock columns get the correct type and can be summed or sorted later.
Step 4: Show the collection in a gallery
Insert a Gallery from the Insert menu and set its Items property to the name of the collection:
colProdutosThe gallery now lists every record automatically. Inside it, bind the labels to the fields with ThisItem.Produto, ThisItem.Preco, and ThisItem.Stock. Pick a gallery layout with a title and subtitle to see the data right away without configuring everything by hand.
Step 5: Clear or remove records
To empty the collection entirely, use Clear. To delete a specific record — for example, from a trash icon inside the gallery — use Remove; and to delete by condition, use RemoveIf:
Clear(colProdutos)
Remove(colProdutos, ThisItem)
RemoveIf(colProdutos, Stock = 0)Verify the result
Preview the app with F5 and click the button you created: the gallery should fill in immediately. To confirm the exact content, add a label with CountRows(colProdutos), which shows how many records exist. You can also open the Variables menu in the left pane of Power Apps Studio and see the collection listed under Collections, with a preview of the real data.
Conclusion
With ClearCollect, Collect, and Remove you can already create and manage in-memory data in Power Apps. The next step is connecting the collection to a real source: use Patch to save the changes to Dataverse or SharePoint, or SaveData and LoadData to store the data on the device and enable offline work. Which of your app's screens would benefit most from loading its data once into a collection?