Skip to main content

Notifications

Community site session details

Community site session details

Session Id : bQm+wseu0I2PBG2HEB1SvA
Power Apps - Building Power Apps
Answered

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?

Like (0) ShareShare
ReportReport
Posted on 7 Jul 2021 10:43:55 by 825

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 

Tapesh_0-1625654309322.png

But the items are unchecked 

Tapesh_1-1625654348571.png

 

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?

Tapesh_2-1625654426747.png

Final result 

Tapesh_3-1625654536751.png

 

The code onCheck :

 

 

 

Set(
 varSequence,
 CountRows(ExportDataGal.AllItems)
);
Collect(
 ExportData,
 {
 unique_id: varSequence,
 data: ThisItem
 }
);

 

 

 

The code on UnCheck :

 

 

 

Remove(ExportData, 
 {
 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. 

  • Verified answer
    Tapesh Profile Picture
    825 on 08 Jul 2021 at 11:31:01
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    Hi @Anonymous @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),
    Collect(
     ExportData, ThisItem
    ));

     

     

    OnUncheck

     

     

    Remove(ExportData, ThisItem)

     

    On Items property of gallery

     

     

     

    ForAll(
     Sequence(CountRows(ExportData),0),
     {
     myRecord: Last(FirstN( Sort (ExportData , ID,Ascending ),Value +1)),
     rowNumber: Value
     }
     )

     

     

     

     



    Tapesh_0-1625743671698.png

     

  • Community Power Platform Member Profile Picture
    on 07 Jul 2021 at 22:55:07
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    @Tapesh 

    For example, if your Gallery is coming directly from SharePoint then you already have a 'unique_id' you can use ie the ID of the items. So, you can simply just use this is the OnCheck & OnUncheck

     

    // OnCheck
    Collect( ExportData, ThisItem)
    
    // OnUncheck
    Remove(ExportData, ThisItem ); 
  • Community Power Platform Member Profile Picture
    on 07 Jul 2021 at 22:35:31
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    @Tapesh 

    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.

  • Tapesh Profile Picture
    825 on 07 Jul 2021 at 18:37:59
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    Hi @yashag2255 

    Thanks for the reply but seems like it is same solution which was provided by @Anonymous 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.



    Thanks

  • yashag2255 Profile Picture
    24,442 Super User 2024 Season 1 on 07 Jul 2021 at 15:21:12
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    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!

  • Tapesh Profile Picture
    825 on 07 Jul 2021 at 12:47:41
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    Hi @Anonymous 

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

    Tapesh_0-1625661870082.png

    OnUncheck

    Tapesh_1-1625661915399.png

     

  • Community Power Platform Member Profile Picture
    on 07 Jul 2021 at 12:39:34
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    @Tapesh 

    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

  • Tapesh Profile Picture
    825 on 07 Jul 2021 at 12:04:24
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    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 ?

  • Tapesh Profile Picture
    825 on 07 Jul 2021 at 12:02:43
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    Hi @Anonymous , 

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

    Tapesh_0-1625659236970.png

    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);
  • zmansuri Profile Picture
    6,048 Super User 2024 Season 1 on 07 Jul 2021 at 11:54:16
    Re: How to remove Items from collection on Uncheck and add on check using CheckBox in Gallery?

    Uncheck:

    Remove(CollectionName,ThisItem)

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard
Loading started
Loading complete