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 / ClearCollect pulling d...
Power Apps
Unanswered

ClearCollect pulling duplicates from SharePoint list when using filter function

(1) ShareShare
ReportReport
Posted on by 145

I'm pulling my datasource into a temporary collection so that I can patch all changes in one go when the user submits the form. I've based my design on Reza Dorani's Editable Grid in Power Apps video: YouTube

 

When loading the data (either editing an existing record or after saving a new one), the collection is pulling duplicates. The only issues I can find online that seem similar is this one Android: ClearCollect resulting in duplicate entri... - Power Platform Community (microsoft.com)

My problem is occurring in the browser as well though.

 

I've altered Reza Dorani's setup slightly, because I need to fetch my records based on a value, as I'm filling this data source with 'child' items of the main list. The button loading my data contains the following OnSelect:

ClearCollect(colGridData,Filter(TC_commitment,checklistID.Id = lastForm));
 
lastForm is filled based on the form that's force submitted in a previous step by using: TransactionChecklistForm.LastSubmit.ID

 

You can see the item ID in the comment column (added it for troubleshooting purposes). All are duplicated except for #6 somehow.

Maarten_DIF_0-1719829314338.png

 

Any insight on how to remedy this is greatly appreciated.

 

Categories:
I have the same question (0)
  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    Hey @Maarten_DIF ,

     

    Could you try and use just this part of the code in a Gallery?

    Filter(TC_commitment,checklistID.Id = lastForm)

    Just to check if the Filter is working as expected. 

     

     

  • Maarten_DIF Profile Picture
    145 on at

    Hi @DBO_DV ,

    That works as expected:

    Maarten_DIF_0-1719835137882.png

    Hacked some columns together to be able to see. The first column is ThisItem.ID, the last is the ThisItem.checklistID.Id

     

    Kind regards,
    Maarten

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    Could you then try this: 

    With({FilteredData:Filter(TC_commitment,checklistID.Id = lastForm)},
    ClearCollect(colGridData,FilteredData)
    )

    Let me know how this works for you.

     

  • Maarten_DIF Profile Picture
    145 on at

    Hi @DBO_DV, still the same unfortunately.

     

    Tried to create a new entry entirely and behavior is also the same. The filtering by checklistID.Id = lastForm works as expected with any of the expressions listed in this thread, it's just the entries for the specific checklistID that are duplicating.

    I do notice that sometimes it duplicates all of them, and sometimes the first ID is not duplicated (like ID 6 in the initial screenshot).

  • Maarten_DIF Profile Picture
    145 on at

    One thing I noticed on the duplicate records is that one seems to be from SharePoint, because it contains all the data like created time/by, whilst the other seems to be only created in the temporary collection (colGridData) and it only contains the data points that are added by the app (ID, amount, category in this snip):

    Maarten_DIF_0-1719912078279.png

     

    Some additional information, which might help troubleshooting:

    The columns in the gallery template all have the following in their OnChange: Select(Parent)

    The Gallery OnSelect is as follows:

    Patch(colGridData,ThisItem,
     {
     ID: ThisItem.ID,
     checklistID:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
     Id:ThisItem.checklistID.Id,
     Value:ThisItem.checklistID.Value},
     rowNumber: Value(FundCommitments_rowNumber.Text),
     category: {Value: "Fund Commitments"},
     commitmentType: {Value: FundCommitments_commitmentType.Selected.Value},
     amount: Value(FundCommitments_amount.Text),
     comment: FundCommitments_comment.Text
     }
    );

     

    The (later invisible) button btnLoadDataTCCommitment has the following OnSelect:

    ClearCollect(colGridData,Filter(TC_commitment,checklistID.Id = lastForm));

    The (later invisible) button btnSaveDataTCCommitment has the following OnSelect:

    Patch(
     TC_commitment,
     UpdateIf(
     colGridData,
     Created = Blank(),
     {ID: Blank(),checklistID: {Id:lastForm,Value:lastForm}}
     )
    );
    Remove(TC_commitment,colDelete);
    Clear(colDelete);
    Select(btnLoadDataTCCommitment);

    The trash icon in the gallery has the following OnSelect:

    Collect(colDelete,ThisItem);
    Remove(colGridData,ThisItem);

    Explanation of the SaveData:

    It patches the SharePoint list (TC_commitment) with the temporary collection colGridData from the gallery, but first updates the ID and checklistID if it's an item that does not yet exist in SharePoint.

    It removes any items that were added to the colDelete collection by the user clicking the trash icon.

    After patching, it loads the data fresh from the SharePoint list by selecting the load button.

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    could you try something else? 

    use the Distinct function. This will display only one time the same Value :

    With({FilteredData:Filter(TC_commitment,checklistID.Id = lastForm)},
    ClearCollect(colGridData,Distinct(FilteredData,Id))
    )

     

  • Maarten_DIF Profile Picture
    145 on at

    @DBO_DV didn't get any results with that.

     

    Did some more testing with the following code in ClearCollect:

    Filter(TC_commitment,checklistID.Id = lastForm)

     

    To ensure no funny business with the editor, I published my version and went in as 'user'.

     

    The issue seems to occur consistently when there are less than 6 rows in the child list. Seems like an arbitrary number, but the behavior is consistent. When there's 6 or more rows, the app behaves as it should. I'm really stumped on this one.

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    I have an idea. 

     

    You could use the distinct function. Distinct on ID . This will give you a table with just one column called Value. 

    Distinct(Filter(TC_commitment,checklistID.Id = lastForm),Unique Identifier)

    Then you can use a LookUp to get the rest:

    LookUp(TC_commitment, UniqueIdentifier=THisItem.Value)

     

     

     

  • Maarten_DIF Profile Picture
    145 on at

    Not sure if I follow. I tried to build something in the Load Data button based on your comment but it won't compile:

     

    With({FilteredData:Distinct(TC_commitment,ID)},
    LookUp(TC_commitment,ID = ThisItem.Value,FilteredData)

     

     

    Also tried this, but it gives incompatible data type (table vs number):

     

    With({FilteredData:Distinct(TC_commitment,ID)},
    ClearCollect(colGridData,LookUp(TC_commitment, FilteredData.Value = ThisRecord.ID)

     

     

    EDIT:

    Changed it to this and that did compile, but it's not pulling in any results:

    Distinct(Filter(TC_commitment,checklistID.Id = lastForm),ID);
    ClearCollect(colGridData, LookUp(TC_commitment, ID = ThisRecord.ID)

     

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    Let me explain: so you can Put this in a Gallery as Items: 

    Distinct(Filter(TC_commitment,checklistID.Id = lastForm),Unique Identifier)

    you 'll  have a Table with one column Named Value. 

     

    with this one column you can make changes on other columns of the same record.

     

    This way could help you solve the error since Distinct will always hold back any duplicates.

     

     

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 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard