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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,720)