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 / Logical problem Last o...
Power Apps
Answered

Logical problem Last or Max in a collection

(0) ShareShare
ReportReport
Posted on by 648

Hello 
How can I create a collection where I select unique email addresses, but the most recently added one in case of duplicates? This database only has the "email" adress column.

I been tryning with this code , but maybee it sholud be lastN , tricky for me 



ClearCollect(UniqueEmails;
Distinct(
AddColumns(
studentloggain;
"MaxCreated";
Max(Value(Filter(studentloggain; email = ThisRecord.email).Created))
);
email
)
)

Categories:
  • Xeon0021 Profile Picture
    116 on at

    Just from the context: Does it really matter if you want all unique email addresses whether they were inserted before or after? Because the email address is the same.

     

    To avoid situations like these, I always build a query to check if the record already exists in the data source before patching something in. It might be something to consider for you as well.

  • dalacarelia_196 Profile Picture
    648 on at

    What I need is the most recently added record, and it should be a combination of an email and a created timestamp 


     

  • dalacarelia_196 Profile Picture
    648 on at

    It is a time log that is associated with an email address, and one can log in multiple times in a single day.

  • PowerRanger Profile Picture
    3,458 Super User 2024 Season 1 on at

    @dalacarelia_196 : Could you describe in more details what you are trying to achieve? Dsitinct() will return a single column table! Do you want to filter a large list with many log entries to show for each unique email the latest (youngest) entry 

     

    or

     

    Do you want to get the latest entry of an specific unique email?

     

     

  • Xeon0021 Profile Picture
    116 on at

    I think what he wants is a table with E-Mail adresses and the last time they logged in.

     

    Probably Something like this works?
    First you collect all entries.
    Then you sort it Descending according to the timestamp.
    And then you do another Clearcollect with Distinct.

    -------------------------------------------------------------------------
    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

  • Verified answer
    PowerRanger Profile Picture
    3,458 Super User 2024 Season 1 on at

    @dalacarelia_196 : Have a look at this solution. Does this solve your problem?

     

     

    ClearCollect(
     colLatestDistinctLogEntries,
     AddColumns(
     GroupBy(
     studentloggain,
     "email",
     "GroupedLogItems"
     ),
     "Max Value",
     Max(
     GroupedLogItems,
     date
     )
     )
    )

     

     

    As I don't know your table columns I have assumed that the column where you log the Date is named "date". 

     

    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.

  • dalacarelia_196 Profile Picture
    648 on at

    Sir thank you very much for your time and effort.

    I applied a filter, and it worked perfectly. I sometimes struggle with the logic, so getting assistance with a nudge in the right direction is greatly appreciated. Once again, thank you very much.




    My final code 

    ;;ClearCollect(
    colLatestDistinctLogEntries;
    AddColumns(
    Filter(
    studentloggain;
    kst = "2015"
    );
    "Max Value";
    Max(
    GroupBy(
    Filter(
    studentloggain;
    kst = ddkst.Text
    );
    "email";
    "GroupedLogItems"
    );
    'Skapad'
    )
    )
    )

     

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 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 320

#3
Mohsin Ali Profile Picture

Mohsin Ali 246

Last 30 days Overall leaderboard