web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Prevent Selection of d...
Power Apps
Answered

Prevent Selection of duplicate records in gallery

(0) ShareShare
ReportReport
Posted on by 9

I have a SharePoint List that I'm trying to take all comma-delimited string data from a field and put into a collection so I can try to find if I have any duplicates based on a certain combination.

 

SharePoint List:

TypeStatus
Type 1,Type2,Type3New
Type2,Type3Final
Type 4Final

 

I'd like to load all Types that have a Status of "Final" into a collection.  Then in the app when a status is changed on a record to "Final" I want to pull all Types that have a Status of "Final" into the same collection.  Then I need to check for duplicates in the collection to prevent saving back to SharePoint if there are any duplicate Types for the status of Final.  For example if I change the first record above to Final the app should have duplicate Type2 and Type3 values in the collection and I shouldn't be able to save until the Type or Status column is changed so the Types are no longer duplicated for the Status of Final.

 

I tried a ForAll loop with a Split and that just splits the string into a table but I have 2 records in the collection with a table as the column.  I'm not sure how I could split the string into 1 collection with rows for each value instead of putting them into tables within the collection.  What I'm expecting to see on Start of the app is a collection with the following:

colFinalTypes
Type2
Type3
Type4

 

Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,452 Super User 2025 Season 2 on at

    Hello,

     

    One way to do it (and its just one way, there are many)

     

    1. have a collection that you add everything (just add them all dups too)

    2. have a secondary collection that you run this code

    ClearCollect(myNewDistinctCollection, ForAll(Distinct(collectionWithDuplicates, ThisRecord), Value));

     

    Now you use the myNewDistinctCollection wherever it is you wanted.

     

  • Michael E. Gernaey Profile Picture
    53,452 Super User 2025 Season 2 on at

    Also you don't need to use a For All to split them. I would do a forall around the fact that you have many rows in SP, but I would just use 

     

    ClearCollect (collectionWithDuplicates,Split (myCommaSeparatedString,","));
    
    or
    
    Collect(collectionWithDuplicates,Split (myCommaSeparatedString,","));

     

    hope that helps

  • Verified answer
    jjbring Profile Picture
    9 on at

    Thanks for the reply.  I ended up going in a different direction, but I was able to resolve this.  In the OnChange event of my combobox I variables for each type (since there are only 5) to a count of the times they are used then I can check those variables count to show/hide the save button and also throw "notify" message for the user to know which type has more than one selected.

     

    Example code for a couple types onChange property of the Combobox and dropdown fields:

    Set(varType1RowCount,CountRows(Filter(Gallery1.AllItems,dd_Status.Selected.Value = "Final" && "Type 1" in cb_Type.SelectedItems)));

    Set(varType2RowCount,CountRows(Filter(Gallery1.AllItems,dd_Status.Selected.Value = "Final" && "Type 2" in cb_Type.SelectedItems)));

  • Michael E. Gernaey Profile Picture
    53,452 Super User 2025 Season 2 on at

    As the saying goes 🙂 whatever works.

    But I would suggest changing to contect variables rather than global variables

     

    Just a suggestion so its becomes a pattern.

     

    Cheers

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard