Are you facing any difficulties removing duplicate rows from a Power Apps collection? no need to worry!
Follow this Power Apps tutorial to learn complete information about how to remove duplicate rows from a Power Apps collection and how to use the Distinct() function to remove duplicate values in a Power Apps collection.
Additionally, we will discuss the “ThisRecord” property to remove duplicate rows from the Power Apps collection using a single line of code.
How to Remove Duplicate Rows From a Power Apps Collection
Creating a Power Apps collection makes adding a group of similar items to a table easier. Also, you can easily remove unwanted or duplicate data (columns or rows).
We can use the Distinct() function to remove all the duplicate rows from the Power Apps Collection.
The screenshot below shows three duplicate rows/records [A Tale of Two Cities, Alice in Wonderland, David Copperfield]. When a user clicks on the Button control [Remove Duplicates], these three duplicates will be removed from the collection, and the result will be displayed on the Power Apps Data table control [2nd below image].
To work around it, follow the below-mentioned steps. Such as:
1. Create Power Apps Canvas app -> Select a default screen and rename it to CollectionScreen.
2. Insert a Power Apps Button control [Books Collection] and set its OnSelect property to the code below.
OnSelect = ClearCollect(
colBooks,
{
BookName: "Animal Farm",
Author: "George Orwell"
},
{
BookName: "A tale of two cities",
Author: "Charles Dickens"
},
{
BookName: "Alice in Wonderland",
Author: "Lewis Carrol"
},
{
BookName: "David Copperfield",
Author: "Charles Dickens"
},
{
BookName: "David Copperfield",
Author: "Charles Dickens"
},
{
BookName: "Waste Land",
Author: "T.S Eliot"
},
{
BookName: "Animal Farm",
Author: "George Orwell"
},
{
BookName: "A tale of two cities",
Author: "Charles Dickens"
},
{
BookName: "Alice in Wonderland",
Author: "Lewis Carrol"
},
{
BookName: "David Copperfield",
Author: "Charles Dickens"
}
)
Where,
- colBooks = Power Apps Collection Name
- BookName, Author = Collection Headers/Columns
- “Animal Farm”, “George Orwell” = Collection Rows/Records
Refer to the below image:
3. Then, insert a Data table and set its Items property as:
Items = colBooks
Where,
- colBooks = Power Apps Collection
4. To display the collection fields in the data table control, click on the Edit fields option and add fields as per your need.
5. Now, click the button control to display the Power Apps collection on the data table like below.
6. Here, you can see that, in the Power Apps collection, you can find duplicate rows shown below.
7. To remove these duplicate rows from the Power Apps collection, insert another Power Apps Button control [Remove Duplicates] and set its OnSelect property code like below.
OnSelect = ClearCollect(
colRemove,
ForAll(
Distinct(
colBooks,
ThisRecord
),
Value
)
)
Where,
- colRemove = Power Apps Collection
- ForAll = We can use this function to evaluate the formula for a single record
- Distinct = You can use this function to remove duplicate values from a Power Apps collection
- colBooks = Power Apps Source Collection Name
- ThisRecord = We can use this function to remove all duplicate rows from a collection
8. Then, insert another Data table and set its Items property as:
Items = colRemove
9. To display the collection fields in the data table control, click the Edit fields option and add fields as needed.
10. Now, click the button control [Remove Duplicates] to display the Power Apps collection without any duplicate rows, as shown below.
This is all about how we can remove duplicate rows from a Power Apps collection.
Conclusion
To remove duplicate rows from a Power Apps collection, you may utilize a distinct() function that removes all the duplicate rows.
This Power Apps tutorial explained the Power Apps collection and removing duplicate rows. Then, we discussed removing duplicate rows from a Power Apps collection. Also, we covered how to use the “Distinct Function” and “ThisRecord Property” to remove all duplicate rows in a Power Apps collection.
Furthermore, you may like some more Power Apps tutorials:
- Display Power Apps Gallery Distinct Values
- Sort Power Apps Collection Alphabetically
- Filter a Collection Based On Another Collection in Power Apps
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com