How to Remove Duplicate Rows in Power Apps Collection?

In this Microsoft Power Apps tutorial, we will learn how to remove duplicate rows in 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. And also how to use the Distinct () function to remove duplicate values in a Power Apps collection.

Remove Duplicate Rows in 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 data, like duplicate columns or rows.
  • The screenshot below shows a Power Apps Collection named “Expenses Collection.” In this collection, I have added data with different columns and rows. Also, this collection has some duplicate rows that I don’t want.
  • We can use the Distinct () function in the code below to remove all the duplicate rows from the Power Apps Collection.
  • The image below shows two duplicate records [Grocery, Cab ride]. When a user clicks on the Remove rows button, these two duplicates will be removed from the collection, and the result will be displayed in the Power Apps Data table [2nd below image].
Power Apps Collection Remove Duplicate Rows

To achieve it, follow the below steps. Such as:

  • Open Power Apps with your valid Microsoft 365 credentials -> Select the app where you want to add a Power Apps collection -> Select a screen and rename it to CollectionScreen.
  • Insert a Power Apps Button control (Expenses collection) -> Set its OnSelect property code like below.
OnSelect = ClearCollect(colExpenses,
    {Item: "Grocery", Category: "Food", PurchasDate: "8/30/2023", Amount: 1000},
    {Item: "Wallpapers", Category: "Household", PurchasDate: "8/31/2023", Amount: 1500},
    {Item: "Cab ride", Category: "Car/Trasport", PurchasDate: "9/1/2023", Amount: 900},
    {Item: "Health checkup", Category: "Ford", PurchasDate: "9/2/2023", Amount: 2200},
    {Item: "Grocery", Category: "Food", PurchasDate: "8/30/2023", Amount:1000},
    {Item: "Cab ride", Category: "Car/Trasport", PurchasDate: "9/1/2023", Amount:900},
    {Item: "Loan payments", Category: "Personal", PurchasDate: "9/3/2023", Amount: 2000})

Where,

  1. colExpenses = Collection Name
  2. Item, Category, PurchasDate, Amount = Collection Headers
  3. Grocery“, “Food“, “8/30/2023“, 1000 = Collection Values/Records
How to Remove Duplicate Rows in Power Apps Collection
  • Then, insert a Data table and set its Items property as:
Items = colExpenses
  • To display the collection fields in the data table control, click on the Edit fields option and add fields as per your need.
How to Remove Power Apps Collection Duplicate Rows
  • Now, click the button control [Expenses collection] to display the Power Apps collection like below.
How to Remove Duplicate Rows from Power Apps Collection
  • Here, you can see that, in the Power Apps collection, you can find duplicate rows shown below.
How to Remove Duplicate Rows from a Power Apps Collection
  • To remove these duplicate rows from the Power Apps collection, insert another Power Apps Button control (Remove rows) and set its OnSelect property code like below.
OnSelect = ClearCollect(colRemoveRows,ForAll(Distinct(colExpenses,ThisRecord),Value))

Where,

  1. ClearCollect = We can use this function to delete all the records from a collection then add a different set of records to the same collection.
  2. colRemoveRows = You can set a collection to remove duplicate rows.
  3. ForAll = We can use this function to evaluate the formula for a single record.
  4. Distinct = You can use this function to remove duplicate values from a Power Apps collection.
  5. colExpenses = It is our Power Apps collection name.
  6. ThisRecord = We can use this function to remove all duplicate rows from a collection.
Remove Duplicate Rows in Power Apps Collection
  • Then, insert another Data table and set its Items property as:
Items = colRemoveRows

To display the collection fields in the data table control, click on the Edit fields option and add fields as per your need.

How to Remove Duplicate Rows using a Power Apps Collection
  • Now, click on the button control [Remove rows] to display the Power Apps collection without any duplicate rows, as shown below.
Remove duplicate rows from a Power Apps collection

This is all about how we can remove duplicate rows from a Power Apps collection.

Also, you may like some more Power Apps tutrorials:

Conclusion

Whenever you want to remove duplicate rows from a Power Apps collection, you can use a distinct function to delete all duplicate rows.

Here, from this Microsoft Power Apps tutorial, we learned all about the Power Apps collection and removing duplicate rows. Then, we discussed how to remove 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.