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 / Unique values by condi...
Power Apps
Answered

Unique values by condition in Collection

(0) ShareShare
ReportReport
Posted on by 8

Hi 

 

I want remove some record inside a collection, I try with group by but I cant get the original structure of the collection, I´m not sure if I need to do a ForAll of this group by and return the first record of each grouped record

I also try distinct function but doesn´t do that we need.

 

The original collection is like this:

 

[
{ date: 2021-06-08, title: A1 },
{ date: 2021-06-07, title: A2 },
{ date: 2021-06-07, title: A3 },
{ date: 2021-06-04, title: A4 },
]

 

 

And I need the get something like this (it´s like a a SQL group by date):

 

[
{ date: 2021-06-08, title: A1 },
{ date: 2021-06-07, title: A2 },
{ date: 2021-06-04, title: A4 },
]

 

 

thanks a lot!

Categories:
  • BCLS776 Profile Picture
    8,994 Moderator on at

    Sounds like you want to use a RemoveIf():

    RemoveIf(myCollection, title = "A3")
  • lucasm107 Profile Picture
    8 on at

    Thanks but I want to remove the element if I already have one item with the same date.. something like a group by sql

  • Verified answer
    StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    Hi @lucasm107

     

    Get unique data from the collection. In this case, colFirstItem has all unique data

    ClearCollect(
     colSample,
     {
     date: "2021-06-08",
     title: "A1"
     },
     {
     date: "2021-06-07",
     title: "A2"
     },
     {
     date: "2021-06-07",
     title: "A3"
     },
     {
     date: "2021-06-04",
     title: "A4"
     }
    );
    ClearCollect(
     colDistinct,
     Distinct(
     colSample,
     date
     )
    );
    Clear(colFirstItem);
    ForAll(
     colDistinct,
     Collect(
     colFirstItem,
     First(
     Filter(
     colSample,
     date = Result
     )
     )
     )
    );

     

  • StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    Hi @lucasm107 

     

    Please let us know if anything needs on your post. We can help with this.

     

    "Please do not forget to give kudos if you find the suggestion helpful or Accept it as a solution if works fine to help other users to find it useful. "

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

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 120

Last 30 days Overall leaderboard