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 Apps / Remove records from co...
Power Apps
Answered

Remove records from collection if condition

(0) ShareShare
ReportReport
Posted on by 14
 
Hello,
 
I am struggling with an collection in my App. It has four columns - Date, Person, number and created. Acually it has more columns (holiday leave table, where people submit holiday but they can cancel as well), So basiclly it looks like below:
 
Date                       Person                     created
01.01.2023             Michael                   01.02.2023
01.01.2023             Michael                   01.03.2023
01.01.2023             Michael                   01.04.2023
01.01.2023             Michael                   01.05.2023
01.01.2023             Michael                   01.06.2023
01.02.2002             Michael                   01.06.2023
01.01.2023             Anna                       01.02.2023
01.01.2023             Anna                       01.03.2023
01.02.2002             Anna                       01.06.2023
 
I'd like to count the rows of each person with the same date. If it's even (it means holiday is canceled), remove all records, if uneven, save only the the last created and remove the others. The result should look like this: 
 
Date                       Person                     created
01.01.2023             Michael                   01.06.2023
01.02.2002             Michael                   01.06.2023
01.02.2002             Anna                       01.06.2023
 
Does anyone have an idea? Thank you. 
 
Categories:
I have the same question (0)
  • Verified answer
    PowerLiebhaberi Profile Picture
    14 on at
    This is my first post and I posted in the wrong forum. However I recieved an answer there which I'd like to share with the other amazing Powerappers :-)
     
    ClearCollect(
        GroupedCollection,
        AddColumns(
            GroupBy(
                MyCollection, // your collection name.
                Date,
                Person,
                GroupedRecords
            ),
            RecordCount,
            CountRows(GroupedRecords),
            created,
            Last(
                SortByColumns(
                    GroupedRecords,
                    "created",
                    SortOrder.Ascending
                )
            ).created
        )
    );
    ClearCollect(
        FinalCollection,
        ForAll(
            GroupedCollection,
            If(
                Mod(
                    RecordCount,
                    2
                ) = 1, // checking is odd count.
                ThisRecord
            )
        )
    );
  • Verified answer
    timl Profile Picture
    36,393 Super User 2025 Season 2 on at
    Hi  PowerLiebhaberi 
     
    Here's a formula to create the example collection that you posted.
     
    ClearCollect(
        colHolidays,
        { Date: "01.01.2023", Person: "Michael", created: "01.02.2023" },
        { Date: "01.01.2023", Person: "Michael", created: "01.03.2023" },
        { Date: "01.01.2023", Person: "Michael", created: "01.04.2023" },
        { Date: "01.01.2023", Person: "Michael", created: "01.05.2023" },
        { Date: "01.01.2023", Person: "Michael", created: "01.06.2023" },
        { Date: "01.02.2002", Person: "Michael", created: "01.06.2023" },
        { Date: "01.01.2023", Person: "Anna", created: "01.02.2023" },
        { Date: "01.01.2023", Person: "Anna", created: "01.03.2023" },
        { Date: "01.02.2002", Person: "Anna", created: "01.06.2023" }
    );

    This formula will build a collection that returns the records for a person with only a single date.
     
    ClearCollect(colOddRecords,
    Filter(AddColumns(
        GroupBy(
            colHolidays,
            Date,
            Person,
            GroupedData
        ),
        RecordCount,
        CountRows(GroupedData)
      ), Mod(RecordCount,2) =1)
    );

    Taking this grouped data, you can retrieve the created date (and other fields related to the last created record for the person) like so.
     
    ClearCollect(colResult, 
            AddColumns(colOddRecords, 
               created, 
            First(Sort(GroupedData,created,SortOrder.Descending)).created)
    );

    This will give the result that you're looking for.



     

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…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard