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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Delete record from col...
Power Apps
Answered

Delete record from collection not working where on Excel sheet it did

(0) ShareShare
ReportReport
Posted on by 140

I all,

 

I have a problem to remove a record from a collection. I have this line of code:

Remove(collectionUsers; GalleryUsers.Selected)

 

It was working fine when the gallery had a Excel sheet as a data source. So the question is why is the remove statement not working on my collection? (I didn’t forget to change the items in the gallery from the Excel sheet to the collection, so that is not the problem).

Categories:
  • eka24 Profile Picture
    20,925 on at

    Remove(collectionUsers, ThisItem)

  • AGroegelich Profile Picture
    140 on at

    Unfortunate Remove(collectionUsers, ThisItem) gives an error in my app. The reason must be that the delete button is not placed in the gallery itself, but on a topbar label outside the gallery. So ThisItem is probably not in the scope.

     

    However I found a workaround: I mark the record as deleted with the Patch statement. Than I can deal with this once the collection is written back to the Excel sheet.

  • AGroegelich Profile Picture
    140 on at

    It still doesn’t make sense to me that a line like:

    Remove(collectionUsers; GalleryUsers.Selected)

    doesn’t work for a collection. The same line is working when the data source is an Excel sheet instead.

     

    For the time being a solved by modifying the code to this:

    Patch(collectionUsers; GalleryUsers.Selected; {Updated: "Deleted"});;
    RemoveIf(collectionUsers; Updated = "Deleted")

     

    The documentation on the Remove statement says: “For collections, the entire record must match.” I am a newbe to Powerapps so can someone enlighten me what that means. I want to understand what is going on.

  • eka24 Profile Picture
    20,925 on at

    @AGroegelich 

        I have gone through your issue and realised the following;

    1. Putting the remove outside the Gallery removes the first item on the list of your Gallery. This mean that at any point in time you want to remove the first item. if this is not the case and you want to remove any specific record apart from the first, then placing the remove inside the Gallery is the best option

    2. After testing both table and collection with remove button outside the Gallery, the record in the table was removed but that of the collection was not removed. this is exactly what you said.

    3. The reason in my view is that, a collection is linked to a table so removing from the collection using does not affect the original source. It is only after patching or saving to the record that it affect the original table.

     

     

    If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

     

     

     

  • AGroegelich Profile Picture
    140 on at

    Hi @eka24,


    3. The reason in my view is that, a collection is linked to a table so removing from the collection using does not affect the original source. It is only after patching or saving to the record that it affect the original table.

    That makes sense. But I anxious to know why I cannot remove a record from a collection in the same way as with a table in Excel. Even more because my workarround is working.

  • eka24 Profile Picture
    20,925 on at

    The removal is temporary. It does not affect that table. May be am not doing something right.

     

    1. I created a collection

    2. Using patch and removeif as you did, it removed the record as you said

    3. But when i clearcollect the record reappears. this indicates that the removal did not affect the original table

    4. Kindly check your datasource if it permanently removed the record

     

     

    If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

  • Verified answer
    AGroegelich Profile Picture
    140 on at

    Hi  @eka24  ,

     

    I cheat… 😁

     

    True either Patch or Collect don’t remove the record from the original table, so a ClearCollect will return the deleted records too. Furthermore I also found that collect doesn’t modify a record from the original table.

     

    I added an extra column called Updated to both the original table and the collection. Default the values in this column are set to “No”. When I delete a column I mark it as “Deleted”. Likewise I mark records with “Inserted” or “Changed”.  When I save the collection to the Excel sheet these columns a written too.

     

    I also do a ClearCollect to refresh the collection which includes the previously deleted records. But – and here is the cheating part – I also do a

    RemoveIf(cUsers; Updated = "Deleted");; 
    UpdateIf(cUsers;Updated <> "No";{Updated: "No"})

    which makes that I get a new fresh collection to continue working.

     

    So the Excel sheet itself has still the deleted records, which is good because the Excel sheet in its turn will be synchronized with an SQL database. Records marked as “Deleted” will be removed from the database on synchonization.

  • eka24 Profile Picture
    20,925 on at
    So is your problem resolved, then mark as a solution
  • NWPMO2021 Profile Picture
    8 on at

    I found that I was having an error due to having a every-other-row highlighting formula placed on my gallery.  Once I removed this formula from the items property on my gallery, and returned it to the default Collection name, the Remove(collectionUsers, ThisItem) worked.  Not sure if that will help anyone else who was stuck, but that is what was causing the problem for me.

  • EEJ009 Profile Picture
    6 on at

    Can you please explain more of how you mark them as deleted, inserted or changed?


    Thanks

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard