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 / AddColumns to Collecti...
Power Apps
Answered

AddColumns to Collection Help

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I cannot figure out how to add a new column to a local collection based on the value of another cell in the collection.

 

What am I missing?

 

  • User clicks "Add Note" icon
  • Popup appears with Text Input box
  • User types text into the input box
  • User clicks "Save" button
  • Save button OnSelect property set to: 
    • AddColumns(
       Filter(<collection_name>,
       <column_1> = true),
      "<new_column_name>",
      input_box.Text)
  • I want the column and value to be added only for the record which matches <column_1> = "true". 

Racking my brain here! I looked over @mr-dang's example here, but it doesn't match my circumstance... Any ideas?


Thanks ahead

Categories:
  • Verified answer
    CarlosFigueira Profile Picture
    Microsoft Employee on at

    AddColumns doesn't change the collection that is passed to it - instead it returns a new collection with the newly added column(s). What you likely need to do is to have the extra column when you are creating your local collection, and then use the UpdateIf function to set the values in that column.

     

    In the attached app, I'm using the following formula to initialize the local collection:

    ClearCollect(
     ScoobyDoo,
     AddColumns(
     Table(
     {Id:1, Name:"Scooby Doo", Age:7, Human:false},{Id:2, Name:"Shaggy Rogers", Age:17, Human:true},
     {Id:3, Name:"Fred Jones", Age:17, Human:true},{Id:4, Name:"Daphne Blake", Age:16, Human:true},
     {Id:5, Name:"Velma Dinkley", Age:15, Human:true}, {Id:6, Name: "Scrappy Doo", Age:3, Human:false }),
     "Species", ""));
    UpdateIf(ScoobyDoo, true, { Species: Blank() })

    Notice that I first initialize the "Species" field with an empty string (to define that the column is of type text), and then I clear the value (since I don't have anything there).

     

    In another button, I can then update the collection based on a specified condition:

    UpdateIf(ScoobyDoo, Human = true, { Species: "Homo sapiens" })
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    This is really good information @CarlosFigueira, thank you. I was unaware that AddColumns created a new collection. Your solution makes sense.

     

    What if you don't know how many columns to create upon the initial ClearCollect? 


    Example: 

    * User may add 40 images to a record or just 1. 

     

    Do you have to ClearCollect all 40 image columns even though they won't necessarily be used? 

  • CarlosFigueira Profile Picture
    Microsoft Employee on at

    In this case, where you can have one or more items related to each item in a collection, you can use a second collection, and use filters to manage the relationship between them.

     

    In the example of the attached app (second screen), the relationship is based on the Name property (for simplicity), but you could use some better unique identifier for that.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Ok. I'll play some with your example (sample apps like this are an awesome way to learn!)


    Thanks for the efforts. 

     

    On a side note, any idea why the image below will not show up when the Gallery image is selected? 

    image_issue.png

  • CarlosFigueira Profile Picture
    Microsoft Employee on at

    Gallery3 is a control that lives inside Gallery2 (and is replicated for every row in the gallery), so I'm not sure you can reference it outside the outer gallery - as there is no deterministic way for PowerApps to guess which of the instances of Gallery3 you're talking about. I'm not 100% sure about this, but that would be my guess why you don't get an image there.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hm. It feels like the ".Selected" property would give PowerApps the context it needs to display the image outside the Gallery.

     

    Gallery3.Selected.Image

     

    I'll keep playing with it and let you know what I find out.

     

    Thanks for the engagement!

     

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 395 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 260 Most Valuable Professional

Last 30 days Overall leaderboard