cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Copy content inside collection to another column

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.  

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Copy content inside collection to another column

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
Highlighted
Super User
Super User

Re: Copy content inside collection to another column

@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."

Highlighted
Super User
Super User

Re: Copy content inside collection to another column

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.


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.

Proud to be a Super User!

Regards,
KrishnaV
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
Highlighted
Frequent Visitor

Re: Copy content inside collection to another column

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

 

 

 

 

Highlighted
Super User
Super User

Re: Copy content inside collection to another column

@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."

Highlighted
Super User
Super User

Re: Copy content inside collection to another column

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


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.

Proud to be a Super User!

Regards,
KrishnaV
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
Highlighted
Community Support
Community Support

Re: Copy content inside collection to another column

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Super User
Super User

Re: Copy content inside collection to another column

@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."

Highlighted
Frequent Visitor

Re: Copy content inside collection to another column

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!

 

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,260)