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 / Allow Users to Choose ...
Power Apps
Answered

Allow Users to Choose Columns To Add to a Collection

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello!

 

I am trying to create collection where a user can select which columns to include or exclude in the collection from a Gallery.

 

Currently I allow a user to filter a gallery and based on the filters selected I allow the user to export the data to an excel spreadsheet. The spreadsheet exports with the same default columns every time time (I have chosen to show these columns as default). This is working like a charm.

 

I would like to add additional functionality that would allow a user to choose the columns they would like to include or exclude in the export. 

 

I am hoping to achieve this by allowing the user to select a column to add to the collection for export by selecting a checkbox. If true include that column in the collection, if false do not include it.

 

Below is the code I am currently using and that is working. Hoping to add functionality to allow a user to choose the columns they want to add to the collection instead of the default in the code below.

 

ClearCollect(_ExportCollection2,ShowColumns(GalleryA.AllItems,"{Name}", "Launch_x0020_Date","Prime"));

 

ClearCollect(_ExportCollection,RenameColumns(_ExportCollection2,"{Name}","Initiative Name", "Launch_x0020_Date","Launch Date", "Prime", "Prime"));

 

Set(varFormattedJSON, JSON(_ExportCollection, JSONFormat.IndentFour));

TrackerExporttoCSV.Run(varFormattedJSON)

;Refresh('Out Puts')

; UpdateContext({_Export: "true"})

; Select(ButtonMain)

 

 

I hope this makes sense!

Thank you!!!

Categories:
  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    Since ShowColumns() function only support literal Text in Column Parameter, hence we cannot apply logic into the ShowColumns().

    We have to use If() logic to list Five possible cases(3 columns) as below, although it may looks not clear.

     

    If(
    Checkbox1.Value=true&&Checkbox2.Value=false&&Checkbox3.Value=false, 
    ClearCollect(_ExportCollection2,ShowColumns(GalleryA.AllItems,"{Name}")),
    Checkbox1.Value=true&&Checkbox2.Value=true&&Checkbox3.Value=false, 
    ClearCollect(_ExportCollection2,ShowColumns(GalleryA.AllItems,"{Name}", "Launch_x0020_Date")),
    Checkbox1.Value=true&&Checkbox2.Value=true&&Checkbox3.Value=true,
    ClearCollect(_ExportCollection2,ShowColumns(GalleryA.AllItems,"{Name}", "Launch_x0020_Date","Prime")),
    Checkbox1.Value=false&&Checkbox2.Value=true&&Checkbox3.Value=true,
    ClearCollect(_ExportCollection2,ShowColumns(GalleryA.AllItems,"Launch_x0020_Date","Prime")),
    Checkbox1.Value=false&&Checkbox2.Value=false&&Checkbox3.Value=true,
    ClearCollect(_ExportCollection2,ShowColumns(GalleryA.AllItems,"Prime"))
    )
    
    

     Hope this helps

    Sik

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I thought about this approach as well. The problem is there are another 20 columns that I want to include and the If statement would need to be written multiple times to cover the dozens of possible combinations. 

     

    I was hoping to create a collection based on which checkbox is chosen, essentially move columns in an out of a collection based on whether a checkbox is selected.

     

    I thought this might be achieved by creating a collection specifically for this task as a first step.

     

    Thank you!

  • Verified answer
    v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    Your words inspired me, please try this code, recreate a new collection based on gallery items.

    Clear(colName);
    ForAll(
     GalleryName.AllItems,
     Collect(
     colName,
     {
     'Initiative Name': If(
     Checkbox1.Value,
     '{Name}'
     ),
     'Launch Date': If(
     Checkbox2.Value,
     'Launch_x0020_Date"'
     ),
     Prime: If(
     Checkbox3.Value,
     Prime
     ),
     ... // add more columns here
     }
     )
    )

     Hope this helps.

    Sik

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    In case this helps someone, I had a similar issue. I wanted to allow users to select the columns they wanted, in the order they wanted, and export the data they just filtered to CSV from the Power App. 

     

    If you know in advance what columns and the order they'll be in all you need to do is create a JSON string from the collection like this:

     

    Set(jsonString, JSON(YourCollection, JSONFormat.IndentFour));

     

    Then call a Flow and pass the jsonString and carry out the logic there in whatever way you want.

     

    But if you want to allow users to choose the columns they want and set the order, it's just a bit trickier. You need a separate collection of column data, such as column name, and order number, etc, which you can present to users with a gallery control. Then, just add another jsonString for the column data, and pass both the export data and column data as 2 separate JSON strings to your flow, where you can combine the two sets into a single CSV file that only includes the columns the users wanted and in the order they set.

     

    Good luck!

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 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard