How to use Collections in Power Apps

Introduction:

Power Apps Collections is a core skill for managing temporary data inside your app. Collections are like in-memory tables that let you store, manipulate, and display data without immediately saving it to a data source.

1️⃣ Creating & Populating Collections

#Use CaseFormulaNotes
1Create empty collectionClearCollect(colEmpty, {})Empty placeholder
2Collect single recordCollect(colEmployees, {ID:1, Name:"John"})Adds one record
3Clear and collectClearCollect(colEmployees, EmployeesList)Resets before collecting
4Collect multiple recordsCollect(colEmployees, {ID:1,Name:"John"},{ID:2,Name:"Jane"})Adds multiple rows
5Collect from SharePoint listClearCollect(colSPList, Employees)Pulls SharePoint list

2️⃣ Adding / Removing Items

#Use CaseFormulaNotes
6Add a recordCollect(colEmployees, {ID:3,Name:"Mary"})Simple add
7Remove a record by conditionRemove(colEmployees, LookUp(colEmployees, ID=3))Removes matching record
8Remove multipleRemoveIf(colEmployees, Department="HR")Delegation-safe removal
9Update a recordUpdateIf(colEmployees, ID=1, {Name:"John Smith"})Update fields
10Patch a recordPatch(colEmployees, LookUp(colEmployees, ID=2), {Name:"Jane Doe"})Alternative to UpdateIf

3️⃣ Filtering & Searching Collections

#Use CaseFormulaNotes
11Filter by columnFilter(colEmployees, Department="IT")Returns filtered table
12Search by textFilter(colEmployees, TextSearchBox1.Text in Name)Partial search
13Search with case-insensitiveFilter(colEmployees, TextSearchBox1.Text in Lower(Name))Lowercase comparison
14Top N itemsFirstN(colEmployees, 5)First 5 items
15Last N itemsLastN(colEmployees, 3)Last 3 items

4️⃣ Sorting Collections

#Use CaseFormulaNotes
16Sort ascendingSort(colEmployees, Name, Ascending)Alphabetical
17Sort descendingSort(colEmployees, Name, Descending)Reverse order
18Sort by multiple columnsSortByColumns(colEmployees, "Department","Ascending","Name","Descending")Multi-level sort

5️⃣ Combining / Joining Collections

#Use CaseFormulaNotes
19Append collectionsCollect(colAll, colSPList)Combine two collections
20Join with AddColumnsAddColumns(colEmployees, "FullName", Name & " - " & Department)Add computed column
21Merge unique valuesClearCollect(colMerged, Distinct(col1, Name))Keep unique names
22Lookup joinAddColumns(colEmployees, "ManagerName", LookUp(colManagers, ID=ManagerID).Name)Simple join
23Concatenate valuesConcat(colEmployees, Name & ", ")Returns text string

6️⃣ Grouping & Aggregating

#Use CaseFormulaNotes
24Group by columnGroupBy(colEmployees, "Department", "DeptGroup")Creates sub-table per group
25Count items in groupAddColumns(GroupBy(colEmployees,"Department","DeptGroup"),"Count",CountRows(DeptGroup))Counts per department
26Sum column in groupAddColumns(GroupBy(colSales,"Region","RegionSales"),"TotalSales",Sum(RegionSales,Amount))Aggregation
27Average valueAddColumns(GroupBy(colSales,"Region","RegionSales"),"AvgSales",Average(RegionSales,Amount))Computes average

7️⃣ Handling Large Data Sources

#Use CaseFormulaNotes
28Lazy load top 500ClearCollect(colTop500, FirstN(Employees,500))Useful for large SP lists
29Combine multiple batchesCollect(colEmployees, Filter(Employees, ID>500 && ID<=1000))Pagination pattern
30Delegation-safe filterFilter(Employees, StartsWith(Title,"A"))Works for SharePoint / Dataverse

8️⃣ Collections for UI / Controls

#Use CaseFormulaNotes
31Populate ComboBoxClearCollect(colDepartments, Distinct(Employees, Department))Bind to ComboBox.Items
32DefaultSelectedItems for ComboBoxFilter(colDepartments, Result="HR")Correct for large sources
33Gallery ItemsFilter(colEmployees, Department=cmbDepartment.Selected.Result)Dynamic gallery
34Checkbox listClearCollect(colSkills, ["Power Apps","Power Automate","Power BI"])Bind to checkboxes
35Toggle collectionIf(chkPowerApps.Value, Collect(colSelectedSkills,"Power Apps"), Remove(colSelectedSkills, "Power Apps"))Dynamic selection

9️⃣ Advanced Collection Operations

#Use CaseFormulaNotes
36Remove duplicatesClearCollect(colUnique, Distinct(colEmployees, Name))Single column dedupe
37Flatten nested tableUngroup(GroupBy(colEmployees,"Department","DeptGroup"),"DeptGroup")Flatten back
38Create running totalAddColumns(colSales,"RunningTotal", Sum(FirstN(colSales, ThisRecord.RowNumber), Amount))Requires RowNumber column
39Transform columnAddColumns(colEmployees,"Initial",Left(Name,1))Compute new column
40Sort grouped tableSortByColumns(GroupBy(colEmployees,"Department","DeptGroup"),"Department",Ascending)Sort after grouping

🔟 Miscellaneous / Utility

#Use CaseFormulaNotes
41Store selected items from a GalleryClearCollect(colSelectedEmployees, galEmployees.AllItems)Save user selections
42Toggle all selectionsIf(chkSelectAll.Value, ClearCollect(colSelectedEmployees, colEmployees), Clear(colSelectedEmployees))Bulk select/deselect
43Clone collectionClearCollect(colClone, colEmployees)Copy collection
44Count rowsCountRows(colEmployees)Collection size
45Check if value existsIf(!IsBlank(LookUp(colEmployees, Name="John")), "Exists","No")Validation
46Export to CSV (text)Concat(colEmployees, Name & "," & Department & Char(10))Simple export
47Filter multi-columnFilter(colEmployees, Department="HR" && Title="Manager")Complex condition
48Sort by custom columnSortByColumns(AddColumns(colEmployees,"SortKey",If(Department="HR",1,2)),"SortKey",Ascending)Custom order
49Union two collectionsClearCollect(colUnion, col1); Collect(colUnion, col2)Combine tables
50Intersect collectionsClearCollect(colIntersect, Filter(col1, Name in col2.Name))Items in both

Tips for Working with Collections

  1. Use ClearCollect to reset and populate

  2. Use Collect to append without clearing

  3. Collections store records or tables, not just single values

  4. Always handle delegation when connecting to large data sources

  5. Use Selected / SelectedItems to get control values

  6. Use GroupBy, AddColumns, Ungroup for advanced table manipulation