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 / Copy content inside co...
Power Apps
Unanswered

Copy content inside collection to another column

(0) ShareShare
ReportReport
Posted on by 26

Hi, 

 

I have a simple inventory list in Sharepoint that was imported into a collection in PowerApp for the purpose of updating the products' inventory.  I cannot for the life of me figure out how to overwrite the data in the Previous Inventory column with the data in the Current Inventory column. 

I would prefer to work within the collection itself rather than copying the collection, liaising back and forth through share point - It's a bulk update - copy all records in one column to another.  

 

 

 

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,989 Moderator on at

    @ColinM 
    Please provide sample data if my code doesn't work.

     

    ClearCollect(
     your_collection_name,
     AddColumns(DropColumns(your_collection_name, "Previous Inventory"), "Previous Inventory", 'Current Inventory')
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • KrishnaV Profile Picture
    5,023 on at

    Hi @ColinM ,

     

    try this:

    Patch(collectionName,ThisItem,{previousInventoryColum:CurrentInventorycolumn})

    I am assuming you are clicking on a button as soon as you provide the latest column in a gallery.

    If not you want to iterate through the list, below is the code for you:

    ForAll(collectioName,Patch(collectionName,ID=ID,{previousInventoryColum:CurrentInventorycolumn}))


    I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

    Regards,
    Krishna
    If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.

  • ColinM Profile Picture
    26 on at

    Hi, 

     

    ForAll has rebuffed my efforts noting it cannot operate on items it is trying to patch, and your code noted it expects a record value. 

     

     ForAll(StartInventoryCollection, Patch(StartInventoryCollection, ID = ID, {'Preivous Inventory': 'Current Inventory'}))

     

    Attached is a copy of the imported collection from SharePoint.  

     

    Thanks

    Colin

     

     

     

     

  • mdevaney Profile Picture
    29,989 Moderator on at

    @ColinM 

    FORALL is not necessary.  Just delete the column for Previous Inventory and add a new column called Previous Inventory with the values equal to the Current Inventory column as shown in my example above.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • KrishnaV Profile Picture
    5,023 on at

    I agree with @mdevaney to just copy the value and which will create a new collection with the value duplication. At the end if you want you can clear(old collection)

    collection( oldcollection, new collection)

     

    Regards,

    Krishna

  • Verified answer
    v-xida-msft Profile Picture
    on at

    Hi @ColinM ,

    According to the needs that you mentioned, I think the ForAll function could achieve your needs. Based on the ForAll formula that you provided, I think there is something wrong with it.

     

    I have made a test on my side, please consider modify your formula as below (set the OnSelect property of a button to following) :

    ForAll(
     RenameColumns(StartInventoryCollection, "ID", "ID1"),
     Patch(
     StartInventoryCollection,
     LookUp(StartInventoryCollection, ID = ID1),
     {
     'Preivous Inventory': LookUp(StartInventoryCollection, ID = ID1, 'Current Inventory')
     }
     )
    )

    RenameColumns function, Patch function, ForAll function

     

    Please consider take a try with above solution, then check if the issue is solved.

     

    Best regards,

  • mdevaney Profile Picture
    29,989 Moderator on at

    @v-xida-msft 
    Myself and @KrishnaV  have already agreed that deleting the 'Previous Inventory' column and adding it back with the value of 'Current Inventory' is the way to go.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • ColinM Profile Picture
    26 on at

    Hi,

     

    Thank you everyone who helped - when I attempted to use the AddColumn/DropColumn code PowerApps informed me the column names already existed preventing me from going further.  I broke the code down into steps where I could drop columns but adding the column proved impossible.  It might have something to do with the imported list from SharePoint keeping its internal column name versus the name I had assigned to it. 

     

    Many thanks!

     

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard