Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

Storing Multiple rows data in collection

(0) ShareShare
ReportReport
Posted on by 78
Hello Community,
 
I have a Table grid in Which user can generate multiple Rows. I am trying to Store these multiple Rows data into a Collection called "colLineItemsUpdates" but 
 
ISSUE:  
 
issue is Suppose I have created two rows in a table Row1 and Row2 when I click on Save Icon Onclick it only storing the Row2 data not storing Row1 data
 
Below is my table and Collection Image:
 
 
Thanks for the Support
  • Verified answer
    WarrenBelz Profile Picture
    148,805 Most Valuable Professional on at
    Storing Multiple rows data in collection
    I am getting a bit unclear on what you want here. The issue is that your save button is outside the gallery - if you only want to collect the currently selected row in the gallery
    With(
       {_Item: GalleryName.Selected},
       Collect(
          colLineItemsUpdates,
          {
             Vendor: _Item.txt_Vendor.Value, 
             'Item ': _Item.txt_Item.Value, 
             Description: _Item.txt_Description.Value,  
             Quantity: _Item.num_Input_Quantity.Value,  
             Price: _Item.num_Input_Price.Value  
          }
       )
    )
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee
  • SR-02111122-0 Profile Picture
    78 on at
    Storing Multiple rows data in collection
    The structure you provided is capturing the value from gallery then collecting in collection but in my case I will be capturing the value from canvas table because my gallery is connected to collection "colLineItemsUpdates", then I will be storing the values in collection and then sending it in sharepoint list.
     
    ForAll(
       YourGalleryName.AllItems As _Items,
       Collect(
          colLineItemsUpdates,
          {
             Vendor: _Items.txt_Vendor.Value, 
             'Item ': _Items.txt_Item.Value, 
             Description: _Items.txt_Description.Value,  
             Quantity: _Items.num_Input_Quantity.Value,  
             Price: _Items.num_Input_Price.Value  
          }
       )
    );
  • SR-02111122-0 Profile Picture
    78 on at
    Storing Multiple rows data in collection
    I tried but it was not Working according to my requirement
  • WarrenBelz Profile Picture
    148,805 Most Valuable Professional on at
    Storing Multiple rows data in collection
    Can you please look at the structure I posted. You need to use the ForAll  structure and the As disambiguation operator.
  • SR-02111122-0 Profile Picture
    78 on at
    Storing Multiple rows data in collection
     
    I did some changes, What I am doing right now is Onclick of Add Row button of Tabel. I am creating a new record in collection, plus by using GUID() I am giving the unique ID to the generated Record. This is formula on Add Row button :
     
    Collect(
        colLineItemsUpdates,
        {
            ID: GUID(),
            Vendor: "",
            'Item ': "",
            Description: "",
            Quantity: 0,
            Price: 0
        }
    )
     
    The formula on Save button is:
    // When the Save button is clicked, collect data for each line item into the collection
    Collect(
        colLineItemsUpdates,  // Collection to store line items
        {
            Vendor: txt_Vendor.Value,  // Text input for Vendor
            'Item ': txt_Item.Value,  // Text input for Item
            Description: txt_Description.Value,  // Text input for Description
            Quantity: num_Input_Quantity.Value,  // Text input for Quantity, convert to number using Value()
            Price: num_Input_Price.Value  // Text input for Price, convert to number using Value()
        }
    );
     
    After Applying this formula I added two rows and added some entries in it, but only second row data is captured in collection as you see in image below and ID's are also created in another row of collection. 
    When I click on save button only record is generated in collection with ID but columns didn't contain any data.
    the ID column you are seeing in this related to SharePoint List Items in which I am storing this table data.
    This how my table looks like now:
     
  • WarrenBelz Profile Picture
    148,805 Most Valuable Professional on at
    Storing Multiple rows data in collection
    You need to refer to the Gallery as below (with your gallery name)
    ForAll(
       YourGalleryName.AllItems As _Items,
       Collect(
          colLineItemsUpdates,
          {
             Vendor: _Items.txt_Vendor.Value, 
             'Item ': _Items.txt_Item.Value, 
             Description: _Items.txt_Description.Value,  
             Quantity: _Items.num_Input_Quantity.Value,  
             Price: _Items.num_Input_Price.Value  
          }
       )
    );
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee
  • SR-02111122-0 Profile Picture
    78 on at
    Storing Multiple rows data in collection
    // When the Save button is clicked, collect data for each line item into the collection
    Collect(
        colLineItemsUpdates,  // Collection to store line items
        {
            Vendor: txt_Vendor.Value,  // Text input for Vendor
            'Item ': txt_Item.Value,  // Text input for Item
            Description: txt_Description.Value,  // Text input for Description
            Quantity: num_Input_Quantity.Value,  // Text input for Quantity, convert to number using Value()
            Price: num_Input_Price.Value  // Text input for Price, convert to number using Value()
        }
    );
     
    This is my formula of Save Button
  • Suggested answer
    Garima_PowerPlatform Profile Picture
    170 on at
    Storing Multiple rows data in collection
    *** Chat GPT answer to question *****

    The issue you're describing typically occurs when the logic to save data into the collection overwrites the previous entries, instead of appending them

     Option 1: Use ForAll to Iterate Over All Rows
    If your table is a gallery (e.g., TableGallery), you can iterate through each row and collect data:

    Clear(colLineItemsUpdates);
    ForAll(
    TableGallery.AllItems,
    Collect(
    colLineItemsUpdates,
    {
    Field1: ThisRecord.Field1,
    Field2: ThisRecord.Field2
    }
    )
    )
    • TableGallery.AllItems ensures all rows are included.
    • Use Clear(colLineItemsUpdates) before adding rows to avoid duplication.

    Option 2: Append Data for Individual Rows
    If you're adding data row-by-row (e.g., from a form), use the Collect function while ensuring previous rows aren't overwritten:

    Collect(
    colLineItemsUpdates,
    {
    Field1: InputField1.Text,
    Field2: InputField2.Text
    }
    )

    Ensure this is triggered for each row added to the table.


    Option 3: Patch Collection to Update Specific Rows
    If you want to update existing rows in the collection instead of adding duplicates:

    Patch(
    colLineItemsUpdates,
    LookUp(colLineItemsUpdates, ID = RowID), // Finds the row to update
    {
    Field1: InputField1.Text,
    Field2: InputField2.Text
    }
    )

    This approach is useful if your rows have unique identifiers (RowID).

  • WarrenBelz Profile Picture
    148,805 Most Valuable Professional on at
    Storing Multiple rows data in collection
    Please post (in text) your OnSave code and also your List name and the field names and types you are needing to save.

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1