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 / Collection comparison ...
Power Apps
Answered

Collection comparison and find the most recent one

(0) ShareShare
ReportReport
Posted on by 43

Hello Team, I have 2 collections.

 

Collection1 : LocalChanges with columns ID and TimeStamp

 

Collection2 : ReadTimeDatafromSource with columns ID and Timestamp.

 

So for all IDs from localChanges collection, I want to compare the Timestamp in ReadTimeDatafromSource and find out which one is recent. 

 

FYI TimeStamp is in this format - "5/21/2020 18:00:00" so to just get the timestamp I'm doing Replace( Collection1.Timestamp, 1, 11, "" ) and compare that value in another collection2

 

Can someone please help? I tried too many ways but not working. 

 

Thanks.

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,991 Moderator on at

    @vshah804 

    Perhaps, something like this could work: although it would take some time to execute

    ForAll(
     localCollection,
     If(LookUp(Datasource, ID=ID,localCollection[@ID]).Timestamp < Timestamp,
     Patch(Datasource, ID=ID,localCollection[@ID]), {PatchColumn: localCollection[@PatchColumn]})
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • mdevaney Profile Picture
    29,991 Moderator on at

    @Drrickryp

    Curious to hear your thoughts on this one...

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @vshah804 ,

    Does the "TimeStamp" column in your two collections store the Text String value rather than date time value?

     

    Based on the scenario that you mentioned, I guess the "TimeStamp" column in your two collections store the Text String value rather than date time value, is it right?

     

    If you want to compare the "TimeStamp" column value in your two different collections, you need to use DateTimeValue() function to convert the "TimeStamp" string value into actual date time value, then you could compare the date time value in canvas app.

     

    I have made a test on my side, please take a try with the following workaround:

    Set the OnSelect property of a button to following:

    ClearCollect(
     CompareResult,
     AddColumns(
     LocalChanges,
     "RecentTimestamp",
     If(
     DateTimeValue(LookUp(ReadTimeDatafromSource, ID = LocalChanges[@ID], Timestamp)) > DateTimeValue(LocalChanges[@Timestamp]),
     DateTimeValue(LookUp(ReadTimeDatafromSource, ID = LocalChanges[@ID], Timestamp)),
     DateTimeValue(LocalChanges[@Timestamp])
     )
     )
    )

    after you press above button to execute the ClearCollect function, the compare result would be saved into the CompareResult collection.

    Within the CompareResult collection, there is a RecentTimestamp column, which is used to store the recent timestamp between your two collections for same ID value. You could add a Data Table in your app, set the Items property to following:

    CompareResult

    then enable corresponding columns in this Data Table, then recent timestamp value would show up for each ID.

    Note: I assume that there is no duplicate ID in your individual LocalChanges collection and ReadTimeDatafromSource collection

     

    Please consider take a try with above solution, check if the issue is solved.

     

    Best regards,

  • vshah804 Profile Picture
    43 on at

    @v-xida-msft 

     

    Your solution works like a charm. Wow. Thank a lot for your great help. Appreciate it.

     

    Thank you and have a good long weekend.

  • mdevaney Profile Picture
    29,991 Moderator on at

    @vshah804 

    If your question was answered by @v-xida-msft please Accept As Solution.  We do this so other readers can benefit from the thread and so other solvers know the issue was taken care of.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 846

#2
Valantis Profile Picture

Valantis 532

#3
Haque Profile Picture

Haque 410

Last 30 days Overall leaderboard