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 / Adding a column to an ...
Power Apps
Unanswered

Adding a column to an existing collection

(1) ShareShare
ReportReport
Posted on by 57

I already created a collection on a separate page with the navigation pointed to the page in question. I need to add three new columns to the Collection before I patch it to Sharepoint. 

 

Collect(WCDCOrder, AddColumns(Table('WCDC Branch #'), "Branch #", 'WCDC Branch #'.Text)

 

The issue I'm seeing from this formula is "Cannot use a non-record value in this context. 

 

I need to add three columns "Branch #", "Shipping Address", "Additional Comments". Help is greatly appreciated. 

 

11.PNG

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @BKICK 

    Is WDC Branch # your existing collection?

    If so, consider changing your formula to this:

    Collect(WCDCOrder, AddColumns('WCDC Branch #', "Branch #", 'WCDC Branch #'.Text)

    In other words, drop the Table function as that will produce the error you are seeing.

    I hope this is helpful for you. 

  • BKICK Profile Picture
    57 on at

    @RandyHayes 

     

    Thank you for your reply. The existing collection is WCDCOrder. 'WCDC Branch #' is the text input field I'm trying to add to the collection as a column.

     

    I just tried this one and it says unexpected characters

     

    Collect(WCDCOrder, AddColumns(WCDCOrder, "Branch #", 'WCDC Branch #'.Text)

     

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

    @BKICK 

    So, you're not trying to add a column as much as you are trying to add the data to a record??

    If 'WCDC Branch #' is your control, then are you trying to add a column with a name of the value in that textbox control?  Or are you trying to add the value in the textinput control as a value to a record in the collection?

     

    You will definitely end up with issues trying to collect the same collection like that as well.  You'll most likely see errors indicating that the column already exists.  Consider another collection, or just using the result of the AddColumns in an Items property and skip the collection (if it works for the rest of your needs).

  • BKICK Profile Picture
    57 on at

    @RandyHayes 

     

    Randy, If I create a second collection is there a way to merge both collections together and then patch to a sharepoint list? 

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

    @BKICK 

    That's not an easy quick answer...it depends!  A lot on what you are actually trying to achieve.  If you are pushing the collection back to your datasource, then they need to have the same field signatures.  If not, then you can use other techniques to make it happen...so again, it really depends.

     

    Keep in mind though that functions like AddColumns and other collection/table based formulas will return the entire modified collection (a copy).

     

    So, I'm not sure this directly answers your question, but perhaps if not, supply some more detail on what you are actually trying to achieve.   From your original post, I assume you have these three columns already in your SharePoint data source and that you're not trying to Add the columns in PowerApps.

    And, I would also add that, if your goal is to "build up" an item that you are then planning to submit back to SharePoint, that using a collection to achieve that is probably not the best route - using a record is all you would need OR even better, skip the record, skip the collection and just put your logic in the submit that you need.  Keep in mind that you can access all the controls of all the screens from any place in the app - so, you do not need to "collect" or "store" the values in controls as you go from screen to screen.

  • v-siky-msft Profile Picture
    on at

    Hi @BKICK ,

     

    What is the logic of the code?  - Collect(WCDCOrder, AddColumns(WCDCOrder, "Branch #", 'WCDC Branch #'.Text)

    As @RandyHayes said, AddColumns function returns a shaped table/collection, so we always use ClearCollection to save the shaped table into a new Collection. it is not supported to save to the previous collection.

    BTW, A bracket “)” is missing at the end of the formula, so the correct syntax of code should be:

    Collect(WCDCOrder_1, AddColumns(WCDCOrder, "Branch #", 'WCDC Branch #'.Text))

     

    It will generate a new Collection named WCDCOrder_1, with a "Branch #" column fill with WCDC Branch #' Text.

    I am not sure if this meets your requirments, since the WCDC Branch #' Text is filled into each row.

    If this doesn't work for your case, please share more details about your requirement.

    Sik

     

  • BKICK Profile Picture
    57 on at

    @v-siky-msft@RandyHayes 

     

    Thank you very much for the responses and your patience. I'm very inexperienced and have been self teaching myself through youtube videos. With that said here is what I have and what I'm trying to do. I created a purchasing app for my organization for internal requests. I used excel as my data source and I want to capture whatever is requested in sharepoint. From there build various flows as notifications. 

     

    This is my catalog of items and the logic behind the "Add To Cart" Button. So far so good.

     

    1.PNG

     

    As items are added to the shopping cart they are added to a collection which is then displayed in the checkout screen. 

     

    2.PNG

     

    I can send the collection to Sharepoint and direct the data to the various columns in sharepoint. The challenge I'm facing is getting the three text inputs into Sharepoint as these aren't apart of the collection. My first thought was to add them to the collection as new columns but I couldn't get that far. My second thought was to create a new collection of these three fields and then merge it with the other collection. 

     

    Any advice is greatly appreciated. 

     

    Thank you. 

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

    @BKICK 

    I'm not seeing that you necessarily need to add these to a collection.  If I am understanding correctly, the three input boxes you have are relevant to the entire order.  

     

    Let's start with - what is your patch formula looking like?  You can simply add the three column values in that patch rather than try to get them into a collection.

  • v-siky-msft Profile Picture
    on at

    Hi @BKICK ,

     

    What is the formula you save the Collection to Sharepoint list?

    Could you please share the SharePoint list construct?

    Do you want three texts to appear repeatedly on each line of the order, as follows?

    Product

    Branch #

    Shipping Address

    Additional Comments

    Gloves

    A

    B

    C

    Battery

    A

    B

    C

    If so, I think you can try this.

     

    Collect(WCDCOrder_1, AddColumns(WCDCOrder, "Branch #", 'WCDC Branch #'.Text, "Shipping Address", TextInput2.Text, "Additional Comments", TextInput3.Text))

     

    Then, save WCDCOrder_1 collection to the SharePoint list as before.
    If this doesn't make sense, please share more information.
    Sik

  • srijit23 Profile Picture
    6 on at

    Hi,

    I have a similar issue, I am trying to get data from a dimension table into  a collection and the fill the facts for these from text inputs in a gallery. I want to updateif the collection with data from text inputs and for that I need 3 blank columns added to the existing collection (eg. with 20 dimension records).

    Regards,

    Srijit.

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 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard