cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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

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!

1 ACCEPTED SOLUTION

Accepted Solutions

@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'})
        )
    )
)

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User III
Super User III

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

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!

 

@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'})
        )
    )
)

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Anonymous
Not applicable

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!!

 

 

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,660)