Introduction
In Power Apps Canvas Apps, we often work with collections (ClearCollect, Collect, Patch, etc.) to manage data locally. But here's a common real-world use case.
How do I combine two collections without ending up with duplicate records?
Let’s say you’re pulling data from two sources or building up a cart system, and you don’t want users to see duplicate items.
So in this article, we’ll see step-by-step how to combine collections without duplication using simple Power Fx formulas – no complicated loops or external data needed!
Scenario
Let’s take a simple example,
Collection A: ["Apple", "Banana", "Cherry"]
Collection B: ["Banana", "Date", "Apple", "Elderberry"]
You want a final collection:
["Apple", "Banana", "Cherry", "Date", "Elderberry"]
Step 1. Create Sample Collections.
Let’s define two collections in the OnStart of the app or a button’s OnSelect.
ClearCollect(colA, {Name: "Apple"}, {Name: "Banana"}, {Name: "Cherry"});
ClearCollect(colB, {Name: "Banana"}, {Name: "Date"}, {Name: "Apple"}, {Name: "Elderberry"});
![Collection]()
Now, colA and colB are two collections with possible overlaps.
![Merge collection]()
Step 2. Combine Without Duplicates.
Here's the magic formula.
ClearCollect(
colCombined,
colA,
Filter(
colB,
!Name in colA.Name
)
);
Load your collections into the Gallery Control.
![Gallery Control]()
What does this do?
- It first copies all items from colA.
- Then it filters colB to include only those items not already in colA (based on the Name field).
- This gives you a clean colCombined collection with unique values!
Tip. Case-Insensitive Match
If you're comparing text fields and want to ignore case.
Filter(
colB,
!Lower(Name) in Lower(colA.Name)
)
Bonus: Unique Based on Multiple Fields
Let’s say your items have both ID and Name, and you want to ensure uniqueness based on ID.
ClearCollect(
colCombined,
colA,
Filter(
colB,
!ID in colA.ID
)
);
Testing the Output
To see your final result, just drop a gallery and set its Items to colCombined. You’ll see the deduplicated, merged list!
Conclusion
Combining collections in Power Apps is pretty straightforward, but adding deduplication makes your app cleaner, faster, and more user-friendly. Whether you're building a shopping cart, a filter system, or a custom lookup – this technique can come in handy.
Quick Recap
- Use Filter(colB, !Field in colA.Field)
- Merge using ClearCollect with both collections
- For custom logic, extend with If or Lower() for comparisons
Stay tuned for more Power Apps tricks!
If you found this article useful, do give it a like or share. And feel free to drop your questions in the comments — always happy to help fellow makers!
– Gowtham Rajamanickam, Power Platform Enthusiast