Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Remove records from collection if condition

(1) ShareShare
ReportReport
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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,419 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,492 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans