Skip to main content

Notifications

Announcements

No record found.

Power Platform integration forum
Answered

Remove records from collection if condition

Posted on by 9
Hi everyone,
 
I have a collection in my App. It has four columns - Date, Person, number and created. Acually it has more columns, but 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, 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 has an idea?
Thank you.
  • PowerLiebhaberi Profile Picture
    PowerLiebhaberi 9 on at
    Remove records from collection if condition
    Thank you so much :-)
  • Verified answer
    Sami Ullah Profile Picture
    Sami Ullah 233 on at
    Remove records from collection if condition
    Hi, Please Try This.
     
    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
            )
        )
    );
     


    I have verify with your data.

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Product updates

Dynamics 365 release plans