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 / Updating Collection
Power Apps
Suggested Answer

Updating Collection

(1) ShareShare
ReportReport
Posted on by 33
Hello I have a Gallery feeded by a collection : coll_main (loaded when opening the screen)
In each row of this gallery I have a field called : txt_count_accuse  with this formula das "DEFAULT" entry : 
 
CountRows(Filter(col_liste_accuse; LL_login = lbl_login.Text And LL_accuse = true))
 
 
Now I want to write this txt_count_accuse field back in a new colum in my coll_main
 
I've tried all but no chance. Should I use Update or Patch or whatever, when I try with Patching and ForAll(gallery.allitems) i receive various errors. How can this be possible.
Many thanks 
Best regards
 
 
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Giraldoj Profile Picture
    762 Super User 2025 Season 2 on at

    Hi there

    You can use a combination of ForAll, UpdateIf, and Patch functions. Below are the steps to achieve this:
     

    1. Create a New Column in coll_main:
      First, ensure your coll_main collection has the new column where you want to store the txt_count_accuse value. You can do this by initializing the collection with the new column.
       

      ClearCollect(coll_main, AddColumns(coll_main, "txt_count_accuse", 0));
       
    2. ​​​​​​Update the New Column with the Calculated Value:

      Use a ForAll function to iterate through each item in the gallery and update the corresponding item in coll_main with the txt_count_accuse value.

      Here's the code to achieve this:

      ForAll(
          Gallery1.AllItems,
          Patch(
              coll_main,
              LookUp(coll_main, ID = ThisItem.ID),  // Replace ID with your unique identifier
              {
                  txt_count_accuse: CountRows(Filter(col_liste_accuse, LL_login = lbl_login.Text And LL_accuse = true))
              }
          )
      );


       

    3. Set the Gallery's Items Property:
      Ensure that the Items property of your gallery is set to coll_main so that any changes to the collection are reflected in the gallery.

       

       

      If this helps, please mark it as the solution by clicking "Accept as solution." A "Thumbs Up" would be greatly appreciated if you found the content helpful. Thanks!
       
      LinkedIn:  https://www.linkedin.com/in/jhonatan-giraldo-2b20561b9/

  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,369 Super User 2025 Season 2 on at
    Hi
     
    Since we are an educational bunch, please share what you tried instead of just asking us to do the work for you, especially the errors.
     
    But let me try to help you
     
    Let's start with what you need
    1. A Column in the Collection already has to exist, lets call it FOO and its a Number (since you are using CountRows)
    2. Lets say that in the Gallery its your txt_count_accuse and lets further assume its a Label, since you said Default 
    3. Lets say you have a Button called UpdateStuff
     
    Here is my sample for you.
     
    First I created a Gallery, and 2 Collections
     
    I have MySample, which is a collection with these items
    ClearCollect(MySample,
        {
            TheCount: 0,
            MyString: "one"
        },
        {
            TheCount: 0,
            MyString: "two"
        }
    );
    I then have my second Collection which I filter, like you do so that my Text Input is populated
     
    ClearCollect(TheValues,
        { 
            MyString: "one"
        }
        ,
        { 
            MyString: "two"
        }
    );
    Below you see the screen and the Filter, where I am checking if MyString = "one" and for both it returns 1. Which is ok.
    Now I have to write the code to Update the MySample collection so that they say 1, versus the 0 you see above when I create it.
     
    LOOK BELOW for the Update Code
     
    Ok, so we have the screen and all the collections.
     
    now I want to update the Collection here is the code.
     
    You can see that I loop through AllItems
    I patch MySample(which is the Gallery Items Collection)
    I use ThisRecord as the Row to Update
    And then I use TheCount as my field (my new one)
    And then I use the Value(ofmy textfield.Text)
    ForAll(Gallery1.AllItems,
       Patch(MySample, ThisRecord,
         {
            TheCount: Value(ThisRecord.txt_count_accuse.Text)
         }
       );
    );
     
    And bingo it works
    After pressing my button with the code above my 0's are now 1s
     

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard