web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Create collection with...
Power Apps
Unanswered

Create collection with variable columns based on User input data

(0) ShareShare
ReportReport
Posted on by

I am building an app for filling out a form. The form contains 50+ fields with most not required (data privacy reasons). I'm storing any fields actually filled out by User into a Collection to send up as JSON to a flow. I don't want to send out all 50+ fields, only the ones that actually get populated based on controls such as radio button selection or textbox entries.

 

How can I achieve the end result? Thanks!

Example: 
User A -- Fills out first three questions so collection would be:
Collect(colMyForm,{col1: "Some Text", col2: "Some text", col3: "some text"})

User B -- Fills out questions 1, 2, and 5 (skipping over 3 and 4)
Collect(colMyForm,{col1: "Some Text", col2: "Some text", col5: "some text"})

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    Hi @MAV_CB ,

    Try this

    ClearCollect(
     colMyForm,
     If(
     !IsBlank(col1ControlName),
     {col1:col1ControlName.Text}
     ),
     If(
     !IsBlank(col2ControlName),
     {col2:col1ControlName.Text}
     ),
     If(
     !IsBlank(col3ControlName),
     {col3:col1ControlName.Text}
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Community Power Platform Member Profile Picture
    on at

    Thanks @WarrenBelz . Unfortunately that formula creates three rows of data, instead of just 1 row of data with three columns. I need to have the collection only create a single row of data but have varying number of columns based on user input. 

    Ideally this would work where one row of data's columns vary on the IF statements. Unfortunately it looks like PowerApps doesn't support this so trying other means to iterate through the input controls to identify which to bring in. 

     

    ClearCollect(
     colMyForm,
     If({
     !IsBlank(col1ControlName),
     col1:col1ControlName.Text
     ),
     If(
     !IsBlank(col2ControlName),
     col2:col1ControlName.Text
     ),
     If(
     !IsBlank(col3ControlName),
     col3:col1ControlName.Text
     )}
    )

     

  • Community Power Platform Member Profile Picture
    on at

    Thanks @WarrenBelz . Unfortunately that just creates three rows within the collection. I need to create one row of data, but with those three specific columns that are dynamic based on user input. 

  • WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    Hi @MAV_CB ,

    I have been around in circles with the below, either dropping all columns or dropping none, but strangely the If  logic is valid and works with other things. This may give you the direction I think you need to take. I have tried four collections with the same result.

    ClearCollect(
     colTestFill,
     {
     col1: Test1.Text,
     col2: Test2.Text,
     col3: Test3.Text
     }
    );
    If(
     IsBlank(First(colTestFill).col1),
     ClearCollect(
     colTestFill,
     DropColumns(
     colTestFill,
     "col1"
     )
     )
    );
    If(
     IsBlank(First(colTestFill).col2),
     ClearCollect(
     colTestFill,
     DropColumns(
     colTestFill,
     "col2"
     )
     )
    );
    If(
     IsBlank(First(colTestFill).col3),
     ClearCollect(
     colTestFill,
     DropColumns(
     colTestFill,
     "col3"
     )
     )
    )

     

  • Community Power Platform Member Profile Picture
    on at

    Thanks @WarrenBelz . Unfortunately that logic did not work either as I have 50 attributes. I just ended up collecting all the data and setting NULL where I didn't have values. 

  • WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    Glad you got it working @MAV_CB ,

    A long way around, but that makes sense.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard