cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MattR
Level: Powered On

How to collect values if and only if they will be unique in the destination collection

Scenario: I am gathering records into a collection. I want to add new records to the collection if and only if they will be unique in that collection. Ideally I would be able to specify the column(s) that would be checked for uniqueness (i.e. ID, or FirstName and PhoneNumber, etc.)

 

Example:
I have a collection that contains three records with one 'Name' column:  {Joe, Bob, Sally}

I have a set of people gathered based on membership in teams: {Steve, Rebecca, Joe, Steve}

There are duplicate values between the two collections, and in the second collection.

I would like to evaluate as follows:

 

TempCollection: {Steve, Rebecca, Joe, Steve}

MasterCollection: {Joe, Bob, Sally}

CollectUnique(MasterCollection, TempCollection (,Formula i.e. 'Name' to evaluate based on Name column))

------Steve is collected as he is unique in the destination

------Rebecca is collected as she is unique in the destination

------Joe is not collected as a record with the Name value of 'Joe' exists in the destination

------Steve is not collected as a record with the Name value of 'Steve' exists in the destination

 

The final values would be:

MasterCollection: {Joe, Bob, Sally, Steve, Rebecca}

 

Does this functionality exist in a different form? Does anyone know of an easy way to collect only unique/distinct records into a collection? I currently use a messy set of ForAll(), IsEmpty(), Filter(), Search(), Collect() to accomplish this objective but it has made some formulas long and difficult to interpret.

 

1 ACCEPTED SOLUTION

Accepted Solutions
SoManyQuestions
Level: Powered On

Re: How to collect values if and only if they will be unique in the destination collection

 

Stumbled upon your issue while working on my App. Hope you have found your answer already, but for the others who are having the same problem.

 

I think you will have to build two Collect formulas (one for each collection to add to uniquecollection). When working with multiple collumns simply add a "." after the collection name in order to specify in which column PowerApps has to look. For example:

 

Collection1.ID in Collection2.ID

View solution in original post

3 REPLIES 3
Community Support Team
Community Support Team

Re: How to collect values if and only if they will be unique in the destination collection

Hi MattR,

 

When creating a collection, I am using this function to stop creating duplicate records in the collection.

 

The function I am using is: If(Not(TextInput1.Text in test),Collect(test,{name:TextInput1.Text}))

 

When a name has been already existing in the collection, it won’t be saved again tough I click the button. Hope this could be a reference for you.

4.PNG

 

Please feel free reply if you need more help.

 

 

Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
MattR
Level: Powered On

Re: How to collect values if and only if they will be unique in the destination collection

Hi Mabel,

 

This sounds like it works great for single-column collections. How would it work for a multi-column collection?

 

For example, the value of 'Name' might be duplicate but the value of 'status' and 'note' might be different. I want to collect if and only if the 'Name' is unique, but I don't care if the status and note are the same or different values from what exists.

SoManyQuestions
Level: Powered On

Re: How to collect values if and only if they will be unique in the destination collection

 

Stumbled upon your issue while working on my App. Hope you have found your answer already, but for the others who are having the same problem.

 

I think you will have to build two Collect formulas (one for each collection to add to uniquecollection). When working with multiple collumns simply add a "." after the collection name in order to specify in which column PowerApps has to look. For example:

 

Collection1.ID in Collection2.ID

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,915)