Skip to main content

Notifications

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 284 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

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,067 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,150

Leaderboard

Product updates

Dynamics 365 release plans