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 / Adding additional data...
Power Apps
Answered

Adding additional data to nested collection

(0) ShareShare
ReportReport
Posted on by

I have a simple setup but just can't get it to work. Understanding the logic behind nested collections is just a little too difficult. 

I have simplified my code below:

First I create the general collection with a nested collection under Item2:

 

 

ClearCollect(col_test1, {Item1: "Text", Item2: {Child1: "Random"}});

 

 

How do add (Collect) a new row to the nested collection under Item2?

I just cannot get it to work. 

I get Patch to work, changing "Random" to "Random_new".

 

 

Patch(col_test1,LookUp(col_test1,Item1="Text"),{Item2:{Child1:"Random_new"}})

 

 

But adding a new row to the nested collection is just impossible for me. Can anyone help me?

Thanks!

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    on at

    The way you are doing it,  will always overwrite the Item2 because Item2 is not a collection or a table. It is record with one column. To add a new child to item 2 you can do the following.

    I did this on my end with 2 collections so you can add to them separately. 

    I added this line on the app OnStart property 

    ClearCollect(col_test2, {Child1: "Random"}); ClearCollect(col_test1, {Item1: "Text", Item2: col_test2});

    And this on a button which adds a new item

    Patch(col_test2, Defaults(col_test2), {Child1: "New Random"}); ClearCollect(col_test1, {Item1: "Text", Item2: col_test2});

     

  • Community Power Platform Member Profile Picture
    on at

    Thanks for the explanation, I got it to work. I understand that the principle here is that I create 2 collections and place one inside the other. 

     

    I am planning to use this collection (col_test1) in a nested Gallery, Gallery_Child (Item2: col_test2 collection) inside Gallery_Parent (col_test1 collection). With you solution, I would need as many child collections as records in col_test1.

     

    Keeping your first ClearCollect, is there no way to avoid your second piece of code, meaning adding a new record to Item2 without going through Patch(col_test2)? Can I not add a new record directly referring only to col_test1?

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

    Hi @Triplee23 :

    Do you want to add records to a subtable in the collection?

    My method is to use Split and concat to construct the table to update the data.

    The key is to construct a new table as the value to be updated.

    Case1:The value of Iterm2 is a single column table

    Ceate collection:

     

    ClearCollect(col_test1,{Item1: "Text", Item2: Table({Child1: "Random"})})

     

    Add Record:

     

    Patch(
     col_test1,
     LookUp(col_test1,Item1="Text"),
     {
     Item2: RenameColumns(
     Split(
     Concatenate(
     Concat(
     LookUp(
     col_test1,
     Item1 = "Text"
     ).Item2,
     Child1,
     "#"
     ),
     "#","Random_new"
     ),
     "#"
     ),
     "Result",
     "Child1"
     )
     }
    )

     

    1.JPG

    Case2:The value of Iterm2 is a multiple columns table

    Ceate collection:

     

    ClearCollect(col_test1, {Item1: "Text", Item2: Table({Child1: "Random"})})

     

     Add Record:

     

    Patch(
     col_test1,
     LookUp(
     col_test1,
     Item1 = "Text"
     ),
     {
     Item2: ShowColumns(
     AddColumns(
     Split(
     Concatenate(
     Concat(
     Concatenate(
     LookUp(
     col_test1,
     Item1 = "Text"
     ).Item2.Child1,
     "%%",
     LookUp(
     col_test1,
     Item1 = "Text"
     ).Item2.Child2,
     "%%",
     LookUp(
     col_test1,
     Item1 = "Text"
     ).Item2.Child3
     ),
     Result,
     "#"
     ),
     "#",
     "Random_new",
     "%%",
     "Random_new",
     "%%",
     "Random_new"
     ),
     "#"
     ),
     "Child1",
     First(
     Split(
     Result,
     "%%"
     )
     ).Result,
     "Child2",
     Last(
     FirstN(
     Split(
     Result,
     "%%"
     ),
     2
     )
     ).Result,
     "Child3",
     Last(
     FirstN(
     Split(
     Result,
     "%%"
     ),
     3
     )
     ).Result
     ),
     "Child1",
     "Child2",
     "Child3"
     )
     }
    )

     

    2.JPG

    Best Regards,

    Bof

     

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