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 / Is there a way to coll...
Power Apps
Unanswered

Is there a way to collect, patch, or update my entire gallery to a collection?

(0) ShareShare
ReportReport
Posted on by 50

Hi all!  I have the below gallery that will be used to select various items and assign expense allocation percentages to each item.  Right now I'm only patching/collecting this data to a collection.  Once i finish all of the forms I'll do a ForAll patch to several SharePoint lists, but for right now I'm just saving this data to a collection.  As you can see in the image below I have the "+" icon which will collect/patch the data to the CostCenterCollection and add another line automatically.  Next i have the "Save" icon which is just a patch formula to my collection and doesn't add another line.  What I'm afraid of is someone entering say 5 lines and if they go change a line they've entered and they forget to hit the individual "+" or the "save" button then there most recent change won't be made.  Is there a way to create a overall save button that basically loops through and clicks all the save buttons or is there a formula to patch or update the entire gallery to the collection to ensure the last entry was collected?  Also, should this button be inside the gallery or outside the gallery?

 

Code for "+"

 

Patch(
CostCenterCollection,
ThisItem,
{
CostCenter1: CostCenterCC.Selected.Value,
Allocation1: Value(AllocationCC.Text)
}
);
Collect(
CostCenterCollection,
{
CostCenter1: "",
Allocation1: 0
}
)

 

 

 

Code for "Save"

 

Patch(
CostCenterCollection,
ThisItem,
{
CostCenter1: CostCenterCC.Selected.Value,
Allocation1: Value(AllocationCC.Text)
}
)

 

 

Variables:

Collection = CostCenterCollection

Collection Field Columns = CostCenter1   &  Allocation1

Dropdown box in the gallery for collecting and entry = CostCenterCC

Text input in the gallery for collecting and entry = AllocationCC

 

2023-10-21_11-08-13.png

 

 

Categories:
I have the same question (0)
  • ivan_apps Profile Picture
    2,189 Moderator on at

    I would tie an event to the Next or Previous buttons you have that iterates through all gallery items and pushes them to your collection. That way you ensure even if they go back to forward, their updates are saved.

  • reidt1 Profile Picture
    50 on at

    Yeah i was thinking putting it on the Next button but didn't even think about the previous button that's a great idea.  I just have no clue how to do it.  I wonder if it's some sort of loop that basically hits all the save buttons. 

  • WarrenBelz Profile Picture
    156,404 Most Valuable Professional on at

    Hi @reidt1 ,

    As I spent some time getting to the bottom of what you are doing on this thread, there are a few items you have left out that are needed to give you the solution here - your data source name, the gallery name and the fields that need to be updated. I know the first to be Table1 and have used Gallery1 on the second. I would normally assume the field names to be CostCentre and Allocation (which I will use here), but I see some references to L5_DESC and L6_DESC, so I am not sure.

    The first thing I suggest is to get that Save icon outside the gallery (just use the + to update the collection) and write to your data source

    Patch(
     Table1,
     ForAll(
     Gallery1.SelectedItems As _Gal,
     {
     CostCentre: _Gal.CostCentre1,
     Allocation: _Gal.Allocation1
     }
     )
    )

    The other suggestion I have is if you have access to SharePoint Lists, change to them as Excel is a terrible data source and probably will cause you some unwanted grief going forward.

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

     

  • ivan_apps Profile Picture
    2,189 Moderator on at

    I imagine it would go something like this:

     

    ForAll(

    YourGalleryName.AllItems,

    Select(ThisItem.YourSaveButtonName)

    )

     

    now the above probably isn’t 100% right but the idea is to iterate through the GALLERY (not the collection or data source) items and select (simulate button press) your current item’s save button.  You’ll have to play around with the proper way to reference the current item in the ForAll loop but that should be the concept. Once you have the proper reference within the gallery, all items within the gallery row should be accessible, even the button. Just make sure you capture the button and gallery names correctly. 

  • reidt1 Profile Picture
    50 on at

    ***Edit - I tried this and it didn't work : ( ***

     

    @WarrenBelz 

     

    Thanks again for the help.  L_4 Desc and L-5 Desc are column names in my Table1 which is just the company hierarchy.  It's the Level 4 and Level 5 business unit descriptions that lead all the way down to the cost center level kinda like a Christmas tree hierarchy where L1 is the Company name and expands to all the legal entities and business units within the company until you get to the last level which is the cost centers.  That was the purpose of the cascading dropdowns.  So people could filter through several levels and not be selected from just 1600 cost centers.  

     

    @ivan_apps  and @WarrenBelz  what would be the downside of me adding the below code to the "On Change" field in both my CostCenterCC Dropdown box and AllocationCC input box?  Would that always ensure everything was saved?

     

     

    Patch(
    CostCenterCollection,
    ThisItem,
    {
    CostCenter1: CostCenterCC.Selected.Value,
    Allocation1: Value(AllocationCC.Text)
    }
    )

     

     

    Above Variables:  

    CostCenterCollection is my collection i'm writing to

     

    CostCenter1 and Allocation1: are what i named the fields in the collection when i wrote the ClearCollect code on the Start button page.  It looks like this:  ClearCollect(CostCenterCollection, {CostCenter1: "", Allocation1: 0})

     

    CostCenterCC is the combobox in the gallery

    AllocationCC is the text input in the gallery

     

    The gallery name is Gallery3

     

  • ivan_apps Profile Picture
    2,189 Moderator on at

    No downside that I can think of, you’d be essentially be creating an auto-save feature and can remove each individual save button. 

    Think about adding some error handling in there for the cases where something goes wrong. You are patching a local collection so it should have good performance but if you ever switch to patching the data source directly it may take a couple of seconds to finish the patch, in which case you generally want to add a spinner to show changes are being saved. 
    good luck!

  • reidt1 Profile Picture
    50 on at

    @ivan_apps 

     

    I tried this code but it doesn't want to give me the option to use ThisItem.

     

    ForAll(Gallery3.AllItems,Select(ThisItem.SaveButtonCC))

     

    I did read something about using a toggle or checkbox (hidden) inside the gallery and then have a toggle/checkbox outside the gallery that checks all to run the code.  I may need to try that.  

     

  • reidt1 Profile Picture
    50 on at

    @ivan_apps   I guess I got too excited too soon.  For some reason when i put the same formula that's in my save button in the CostCenterCC "On Change" field it does some wonky stuff.  Not every time but sometimes when you make changes it adds a line and captures multiple items even though I have Multi select set as false.  See below snagit video if you'd like to see what it's doing.  It's very weird.  Maybe I need to create a automatic unique ID field for each line in the gallery and do some type of loop formula to save them individually at the end.

     

    YouTube SnagIt video of issue. 

    https://youtu.be/mzVEL2ZeiIw

     

    Thanks for all of the help

     

  • reidt1 Profile Picture
    50 on at

    What do you think would happen if I did this formula in previous and next?

     

    ClearCollect(CostCenterCollection, Gallery3.Allitems). 

  • WarrenBelz Profile Picture
    156,404 Most Valuable Professional on at

    @reidt1 ,

    Mine was only a suggestion - you only need one save to collection and the + sign is doing this. You also need a "save to data source" and this needs to be outside the gallery. I will drop out now as I avoid three-way conversations.

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
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard