cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bkk
Helper I
Helper I

Distinct rows from a collection

Morning guys, I have a collection as shown in Input collection. Primary key is email address. I want to get distinct rows from this collection in such a way that if Group Name and Is preferred member is provided in that row, it will be selected otherwise get the one with that information blank. Please see the Output collection for an example output. Any help will be greatly appreciated.

Thanks

 

Input Collection

NameEmailGroup NameIs Preferred Member
John DoeJohn.Doe@company.com  
Jimmy DoeJimmy.Doe@company.comGroup 2 
Jane DoeJane.Doe@company.com  
Jimmy DoeJimmy.Doe@company.com  
Jill DoeJill.Doe@company.comGroup 1Yes
John DoeJohn.Doe@company.comGroup 3 
Jimmy DoeJimmy.Doe@company.comGroup 2No

 

Output collection

NameEmailGroup NameIs Preferred Member
Jane DoeJane.Doe@company.com  
Jill DoeJill.Doe@company.comGroup 1Yes
John DoeJohn.Doe@company.comGroup 3 
Jimmy DoeJimmy.Doe@company.comGroup 2No
8 REPLIES 8
Powerplatform01
Post Patron
Post Patron

@bkk 

You can watch this video.Also request you to please subscribe this channel.Your one click helps me a lot.

https://youtu.be/XgOxBudz-8c

BCLS776
Super User
Super User

@bkk, a quick reply to get you started and we can help with specific code later if you need it. To accomplish what you want you will need to:

  • Use GroupBy() using GroupName to bundle your records up
  • Use AddColumns() to bring the Name, Email, and Preferred Member columns to the top level of the collection, if you need them there. The previous GroupBy will nest these fields as part of the grouped records.

Hope that helps!

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

Thanks BCLS776, appreciate the suggestion. Let me try and get back to you.

 

Bkk

mdevaney
Super User
Super User

@bkk 

Here’s a simple formula to do the work for you:

//Duplicate removal code
ClearCollect(colOutputCollection,ForAll(Distinct(colInputCollection, ThisRecord),ThisRecord.Result));

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

bkk
Helper I
Helper I

@mdevaney Thanks. What you have quoted is what I have done, but that does bring in duplicates and hence I know that is not the answer. I have screen shots and code included.

Code on Create Collection

ClearCollect(
    colInputCollection,
    {
        Name: "John Doe",
        Email: "JohnDoe@company.com",
        Group: "",
        IsPRefMem: ""
    },
    {
        Name: "Jane Doe",
        Email: "JaneDoe@company.com",
        Group: "",
        IsPRefMem: ""
    },
    {
        Name: "Jimmy Doe",
        Email: "JimmyDoe@company.com",
        Group: "Group 2",
        IsPRefMem: ""
    },
    {
        Name: "Jill Doe",
        Email: "JillDoe@company.com",
        Group: "",
        IsPRefMem: "Yes"

    },
     {
        Name: "John Doe",
        Email: "JohnDoe@company.com",
        Group: "Group 3",
        IsPRefMem: ""
    },
    {
        Name: "Jane Doe",
        Email: "JaneDoe@company.com",
        Group: "",
        IsPRefMem: ""
    },
    {
        Name: "Jimmy Doe",
        Email: "JimmyDoe@company.com",
        Group: "Group 2",
        IsPRefMem: "No"
    },
    {
        Name: "Jill Doe",
        Email: "JillDoe@company.com",
        Group: "Group 1",
        IsPRefMem: "Yes"
    }
);
 

Create Distinct has following code

ClearCollect(colOutputCollection, ForAll(Distinct(colInputCollection,ThisRecord),ThisRecord.Result));
 

DistinctDistinct

 

mdevaney
Super User
Super User

@bkk 

I disagree.  Your example shows it worked perfectly.  The only duplicate record is for Jane Doe and that gets removed.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

You can disagree, but that is NOT the question I asked in the first place. Please read through the original question. 

Thanks

@bkk 

Yes, you’re right.  That is not the original question.  Please use the approach suggested by @BCLS776.  I’m unable to write the code needed on mobile.

 

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (2,220)