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 / Add and Remove Columns...
Power Apps
Answered

Add and Remove Columns to a collection based on true/false from a checkbox

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello!

 

Is it possible to add and remove columns to a collection based on a true or false value from a checkbox?

 

Looking to do this for multiple columns from the same list allowing a user to add or remove a column to a collection based on whether a checkbox is selected.

 

Thank you!

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Yes, this is certainly possible.  However, keep in mind that Add and RemoveColumns does NOT add or remove columns from the collection...these functions RETURN a table (collection) that would have those columns added or removed.  You could assign that to another collection or variable, or skip direct to your control that you are trying to apply to.

     

    If you have specifics to share that you are in question on, please do so.

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you for confirming, I am stuck on how to do this.

     

    If I were to use a Gallery as my source how would this look?

     

    Assuming the following:

    ClearCollect(CollectionA,Gallery1.AllItems)

     

    Gallery1 Columns: "Name", "Prime", "Launch Date"

     

    Checkbox1 = true - Add "Name" Column to collection

    Checkbox2 = true - Add "Prime" Column to collection

    Checkbox3 = false - Remove (Or exclude)  "Launch Date" from collection

     

    If you are able to provide an example that would be amazing!

     

    Thank you!

     

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Sure thing.  This formula works well...

    ClearCollect(CollectionA,
     ForAll(Gallery1.AllItems,
     Patch(
     If(Checkbox1.Value, {Name:Name}),
     If(Checkbox2.Value, {Prime:Prime}),
     If(!Checkbox3.Value, {'Launch Date':'Launch Date'})
     )
     )
    )

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you, worked like a charm!

     

    If user selects to not include a column in the collection is it also possible to not include the column name as well? If the column data is not included in the collection can the column header be excluded as well?

     

    Thank you!!

     

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Hmmm...dropping or showing columns like that would not be easy.  Since you have a small number of columns (or I believe you might), you would most likely need to wrap in some If statements.

    That's not an easy one...that I can think of.

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

#2
M Bilal Khan Profile Picture

M Bilal Khan 289

#3
Mohsin Ali Profile Picture

Mohsin Ali 228

Last 30 days Overall leaderboard