cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

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
Highlighted
Frequent Visitor

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

4 REPLIES 4
Highlighted
Community Support
Community Support

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
New Member

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.

Highlighted
Frequent Visitor

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

Highlighted
Responsive Resident
Responsive Resident

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

Hello,

 

I ran into this post before I realized I had implemented a solution for entering unique values into collection.

 

This is what I did.

 

If(IsEmpty(Filter(collectionTable,employeeID = ddlEmployees.cboEmployeesOut.eid))
,Collect(collectionTable,

    .... collect colums ... 

  )

) // end if

 

What I did is first I filtered the collection to check if the record exists. You can check on multiple columns for the filter criteria giving you a the ability to match every single column.  

 

So if it returns empty that means the record is not in the table.

 

And I think you can put this in a ForAll loop.

 

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,988)