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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Remove oldest duplicat...
Power Apps
Answered

Remove oldest duplicates from collection

(0) ShareShare
ReportReport
Posted on by 260

Hey all

 

I have a collection called colDATA with many items and columns. I want to remove all the oldest "duplicates" with respect to only two columns; Person and Date. The picture below depicts what I want to achieve. The result should exclude the two highlighted entries as they are oldest duplicates.

 

Snag_2ddf5882.png

 

I have attempted many permutations but they're all throwing a range of errors like "Invalid number of arguments: received 5, expected 2-3", "Invalid number of arguments: received 3, expected 2" and "Name isn't valid. 'Date' isn't recognized".

 

Below is what I've ended up with...

 

ClearCollect(
 colUniqueData,
 ForAll(
 Sort(
 colDATA,
 Person,
 SortOrder.Descending,
 Date,
 SortOrder.Descending
 ),
 If(
 !IsBlank(LookUp(colUniqueData, Person = colDATA[@Person])),
 LookUp(colUniqueData, Person = colDATA[@Person]).Date < colDATA[@Date],
 true
 ),
 {
 Person: colDATA[@Person],
 Date: colTEST[@Date]
 }
 )
);

 

Any ideas appreciated!

 

 

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,921 Most Valuable Professional on at

    Hi @fnanfne ,
    More challenging than you think - below is my best effort - seems to do the job, but I do not have your data.

    With(
     {
     wData: 
     AddColumns(
     GroupBy(
     Filter(
     AddColumns(
     GroupBy(
     Sort(
     colDATA,
     ID,
     SortOrder.Ascending
     ),
     "Person",
    					 "Date",
     "Data"
     ),
     "ID1",
     First(Data).ID,
     "ID2",
     First(Data).ID,
     "Items",
     CountRows(Data)
     ),
     Items > 1
     ),
     "ID1",
     "Data2"
     ),
     "DelItem",
     First(Data2).ID2
     )
     },
     ClearCollect(
     colUniqueData,
     Filter(
     colDATA,
     !(ID in wData.DelItem)
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • fnanfne Profile Picture
    260 on at

    Hi WarrenBeltz

     

    I have tried your code but it does not work for me. I substituted Person and Date with the names of my columns. Not sure about the "Data" field, was that just a variable to connect it all together? Also, the "ID1", "ID2" and "Items" fields, are those again just some variable used with the With function?

     

    Thank you very much for the reply, greatly appreciate your efforts as always!

     

    I'm going to play around with your code to see if I can get it working, I might have just missed a special character somwehere.

  • WarrenBelz Profile Picture
    156,921 Most Valuable Professional on at

    Hi @fnanfne ,

    You can call Data, Data2, ID1, ID2 and Items whatever you want as long as it is consistent in all places they are used (yes, they are Variables)

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 236 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard