Showing results for 
Search instead for 
Did you mean: 
Post Prodigy
Post Prodigy

How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery and add row numbers depending on items in collection?

Hi Experts, 

I have been trying to use the check box to get certain data when the user selects a specific Item and add them to the collection, however, while doing so it adds the records to the collection, but does not remove when a user selects, in fact, it only removes the item from the collection which was last added. 
Please find the screenshot below 


But the items are unchecked 



when I tried to add another 3 items and remove them only one was removed i.e. last entry,  rest are not removed, any idea why is this happing?


Final result 



The code onCheck :




        unique_id: varSequence,
        data: ThisItem




The code on UnCheck :




        unique_id: varSequence,
        data: ThisItem




Could you please help on this if anyone has any idea what's wrong or missing something. 

Thanks a million for taking the time to read and help. 


Accepted Solutions

Hi @Eelman @yashag2255 @zmansuri 

Thanks all for the help, support, knowledge, and time. It really means a lot to me, but finally, I got the solution and the result is as below by using a Forall and sequence function. 
OnCheck :



If ( ThisItem exactin ExportData, Notify("Item already added", NotificationType.Information, 3000),
    ExportData, ThisItem






Remove(ExportData, ThisItem)


On Items property of gallery




            myRecord:  Last(FirstN( Sort (ExportData ,  ID,Ascending  ),Value +1)),
            rowNumber: Value







View solution in original post

Super User
Super User


Firstly, I think you need to adjust your OnCheck to this


unique_id: varSequence+1,
data: ThisItem


Then, your OnUncheck could use this


RemoveIf( ExportData, unique_id = ThisItem.unique_id)


I'm posting this on my iPad so cannot test it but think that should work?

Super User
Super User



Hi @Eelman , 

I tried your way but it did not work , I modified it but same the error, 


However, I tried this but it's removing all the selections not the just one with the Uncheckmark, 

RemoveIf( ExportData, unique_id exactin ExportData.unique_id);

Hi , @zmansuri

Yeah, this one works fine for normal but I also have come additional data which I'm adding to the collection while on check and Uncheck but seems like it does not work for Uncheck only. 
 Any idea why is it so ?


Sounds like some other code is also firing at the same time, what is the full OnUncheck code and do you have any code in the OnSelect of your gallery? If so, post that as well

Hi @Eelman 

Please see the code below I do not have any other code than this one .





Dual Super User II
Dual Super User II

Hi @Tapesh 


You can use the configuration as below:


OnReset or OnVisible -> Clear(CollectionName)


OnCheck: Collect(CollectionName, {Identifier: ThisItem.ColumnName, data: ThisItem})


OnUncheck: RemoveIf(CollectionName, Identifier= ThisItem.ColumnName)


Here, you have to replace ColumnName with the name of column which stores unique values in the gallery.



Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Hi @yashag2255 

Thanks for the reply but seems like it is same solution which was provided by @Eelman in last reply, sorry to say but it does not work for me as I am using a variable and adding the to collection. could you please help with any other way just in a away where I can create an auto-increment number starting from 0 and end at the last item in the collection.  like Sequnece 0,  1, 2, 3, 4, 5. Would be a great help as I can play around then if I get the auto-increment number whe user add the item to the collection and remove vice-versa.



What is the Items property of your Gallery ie how is it built? Currently, there isn't a relationship between the Gallery and the Collection which is why you cannot manage the deletion of records. We need to create a relationship to be able to do what you are wanting to do.

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.


New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,909)