How to Remove Duplicate Rows From a Power Apps Collection?

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].

How to Remove Duplicate Rows in the Power Apps Collection

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:

Remove Duplicate Rows from Power Apps Collection

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.

Remove Duplicate Rows from a Power Apps Collection

5. Now, click the button control to display the Power Apps collection on the data table like below.

How to Remove Duplicate Rows From a Power Apps Collection

6. Here, you can see that, in the Power Apps collection, you can find duplicate rows shown below.

How to Remove Duplicate Rows from Power Apps Collection

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.

How to Remove Duplicate Rows from a Power Apps Collection

10. Now, click the button control [Remove Duplicates] to display the Power Apps collection without any duplicate rows, as shown below.

How to Remove Duplicate Rows in Power Apps Collection

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:

>