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 / Method to Remove items...
Power Apps
Answered

Method to Remove items from local Collection

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have an app with various medical questions that I want to flag and collect a condition everytime the user selects "Yes".  Here is an example of my code behind a toggle button:  If(ynSmoker.Value,Set(ReviewFlag,true);Collect(ReviewItems,"Smoker"),false)

 

So my question would be, what if that user selects Yes, but then reverts back to No?  I need to Remove that item from the collection.  Would it be as simple as "Remove(ReviewItems,"Smoker")?  I dont think it would be that easy I am guessing

 

Thanks,

 

Brad

Categories:
  • timl Profile Picture
    37,301 Super User 2026 Season 2 on at

    Hi Brad,

     

    You're right, it's not that simple! The Remove function works well against connected data sources, but it doesn't work against local collections. I think this is a bug in PowerApps.

     

    https://powerusers.microsoft.com/t5/General-Discussion/Method-to-Remove-items-from-local-Collection/td-p/27157

     

    If you have a unique id that identifies the record that you want to remove from the local collection, a more reliable way is to call the RemoveIf function.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Now I am trying to think logically how to do this.  This questionnaire has around 50 of these medical conditions and if any of them are selected to "Yes", the app needs to capture that and I was thinking a Collection would work just fine (selecting Yes also trips a flag too but that is easy to handle).  As I was working on this, I was thinking if the user selected the wrong toggle or said yes, then reverted back to No, how it would impact that collection. Perhaps I could do a massive IF statment on the Submit button?  Also, I did see that topic that you referred to and I need to revisit it to see if I missed something.

     

    Thanks

  • timl Profile Picture
    37,301 Super User 2026 Season 2 on at

    I think the approach of adding your logic to your Submit button might be best. That way, you don't need to worry about the possibility of a user toggling an answer from 'yes' back to 'no'.

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello @Anonymous, 

     

    Here is the method I use to remove items from a collection. Hope this helps. 

     

    • Use a Gallery with an embedded Checkbox control
    • Checkbox OnCheck property: 
      • Collect(
         <collection_name>, 
         {<column_name_1>: ThisItem.<column_name_1>, 
         <column_name_2>: ThisItem.<column_name_2>}
         )
    • Checkbox OnUncheck property
      • Remove(
         <collection_name>,
         First(
         Filter(
         <collection_name>,
         <column_name_1>=ThisItem.<column_name_2>)
         ),
         All)

     

    Hope this helps your scenario. 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks @ericonlinefor this.  I will try it, and also accepted as a solution for now.  But yes, it is a bit quirky but dont see why it wouldnt work.

     

    Brad

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Cool. The "First(..", "Filter(...", and "All" will likely get you what you need. 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    So I am hoping something like this: If(ynSmoker.Value,Collect(ReviewItems,"Smoker"),Remove(ReviewItems,First(Filter(ReviewItems,Value="Smoker")))) <--This is in the OnSelect of the toggle

     

    The only thing I was unsure of is the column name because there is only one column in this collection and it is not specified so looking at the example here: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/create-update-collection it is Value.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I think you'll need to look closer at your Collect syntax. The curly braces and such.

     

    I believe its Collect(<collection_name>, {<collection_column_name>:<value>})

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    And don't forget the "All". That parses the entire collection and removes all instances of the item. If for some reason the User recorded the same value twice, this would get both of them. 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    And your guidance did work.  I tested it and looked at the Collection data in the IDE and I used this: If(ynSmoker.Value,Collect(ReviewItems,"Smoker"),Remove(ReviewItems,First( Filter( ReviewItems, Value="Smoker" ) ),All ))

     

    I really didnt need a column name as it is set to "Value" automatically and for me right now, that is all good.

     

    Thanks again!

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 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 320

#3
Mohsin Ali Profile Picture

Mohsin Ali 246

Last 30 days Overall leaderboard