web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Delete duplicated item...
Power Automate
Unanswered

Delete duplicated items based on the latest date

(0) ShareShare
ReportReport
Posted on by 83

Hello there,

In SharePoint I have the following list which might contain duplicated items and I want to delete any items with the older Requested date.

anna2109_0-1706539497852.png
Could you please help me how to delete automatically the rows and leave one unique row per ContractorRef with the earliest date?

 

Categories:
I have the same question (0)
  • takolota1 Profile Picture
    4,978 Moderator on at

    @anna2109 

    This template helps find & remove duplicates based on any number of selected columns. And it allows you to control which ones to keep based on how you sort the action that gets the data items.
    https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Find-and-Remove-Duplicates/td-p/2191403 

     

     

    _____________________________________________________________________________

    Subscribe to my YouTube channel

  • David_MA Profile Picture
    13,446 Super User 2026 Season 1 on at

    Doing this will be a bit tricky, but I would try this:

    1. Create a manually triggered flow and use the Get items action to get all of the rows in your list. If it is a large list, you may need to turn on pagination.
    2. Then initialize an integer variable and set its default value to zero named Items.
    3. Initialize a second integer variable and also set its default value to zero named Count.
    4. Follow it with an Apply to each action using the values from the Get items action.
    5. In the Apply to each, add another Get items action but this time use a filter query where ContractorRef eq the ContractorRef of the current item. Also, sort the items by Requested date. You want to sort them in ascending order, which I believe is the default. This will make the newest item the last one.
    6. Add a condition to check if the second get items action returns more than 1 item. If it does, then do the next steps on the yes side of the condition. If no, then that means there is only one item and you don't need to do anything.
    7. Use the Set variable action to set the variable Items created in step two to one less than the number of items found with this expression: sub(length(outputs('Get_items_2')?['body/value']),1). If it finds 5 items, this will calculate to 4 so you delete the four duplicates.
    8. Add a Do until action and set it to run until the variables Items eq Count.
    9. In the Do until action add an Apply to each with the values from the second Get items action.
    10. In the second apply to each action add a delete item action to delete the item (be sure to use the ID from the second get items action to specify the item to delete).
    11. Then use the Increment variable action to increment the count by 1.
    12. Follow the condition with two Set variable actions so you can reset the Count and Items actions back to zero.

    Although, a much easier approach, if you don't yet have a lot of items in your list, would be to create a view in your list and group on ContractorRef and sort by the Requested date. Then manually delete the duplicates. Once you've gotten rid of the duplicates, set the ContractorRef field to require unique values. This way, nobody will be able to add a duplicate ContractorRef to the list in the first place.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
trice602 Profile Picture

trice602 248 Super User 2026 Season 1

#2
David_MA Profile Picture

David_MA 207 Super User 2026 Season 1

#3
Power Platform 1919 Profile Picture

Power Platform 1919 101 Super User 2026 Season 1

Last 30 days Overall leaderboard