web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Power Query
Suggested Answer

Nested gallery

(1) ShareShare
ReportReport
Posted on by 13

Hello everyone,

I am working on a Power Apps application and I need help with the "Save" button formula in the context of a nested gallery. My goal is to save the following information to a SharePoint list: the person's name, the activity, and the type of position selected from a dropdown list.

Here’s a preview of my interface: 

  


 

The data needs to be saved in the SharePoint list, which has the following columns: Date, Collaborator, Activity, and PositionType.

Thank you in advance for your help and advice on how to implement this functionality with a nested gallery!
 
 
 

Best regards,


 

Categories:
I have the same question (0)
  • Suggested answer
    SebS Profile Picture
    4,569 Moderator on at
    Nested gallery
    You could try this just make sure you change name of your data source 

    ForAll(
        gal_Collaborator.AllItems,
        With(
            { varCollaborator: ThisRecord.Collaborator },
            ForAll(
                gal_Activity.AllItems,
                Patch(
                    'SharepointList',
                    Defaults('SharepointList'),
                    {
                        Date: dp_Date.SelectedDate,
                        Collaborateur: varCollaborator,
                        Activité: ThisRecord.ActivityName,
                        TypePoste: drp_Position.Selected.Value
                    }
                )
            )
        )
    );
    Notify("Activities saved successfully!", NotificationType.Success)

    Not best Use of ForAll (Should not use it in big data sets as loop) but should work with Your example :)
  • AN-05111234-0 Profile Picture
    13 on at
    Nested gallery

    Thank you SebS, I tested your formula, but with the double ForAll, the data is not saved. When I keep just the first ForAll, the data is saved, but when I add the second ForAll to access the data from the nested gallery, nothing is saved.

     

    I modified the formula, but still nothing. Do you have any other ideas?

     

       ForAll(
           Gal_Collaborateur.AllItems, 
           With(
               {
                   CollaborateurName: ThisRecord.Personne 
               },
               ForAll(
                   Gal_Activité.AllItems, 
                   Patch(
                       'Suivi des activités',
                       Defaults('Suivi des activités'),
                       {
                           Collaborateur: CollaborateurName, 
                           Activité: ThisRecord.Activité, 
                           TypePoste: ThisRecord.ddl_Valeur.Selected.Value,  
                           Date: Datepicker.SelectedDate 
                       }
                   )
               )
           )
       );
  • WarrenBelz Profile Picture
    152,811 Most Valuable Professional on at
    Nested gallery
    Firstly @SebS's provided code is valid and should technically work - so should this
    ForAll(
       Gal_Collaborateur.AllItems As _G1,
       ForAll(
          _G1.Gal_Activité.AllItems As _G2,
          Patch(
             'Suivi des activités',
             Defaults('Suivi des activités'),
             {
                Collaborateur: CollaborateurName, 
                Activité: _G2.Activité, 
                TypePoste: _G2.ddl_Valeur.Selected.Value,  
                Date: Datepicker.SelectedDate 
             }
          )
       )
    );
    but I have been down this blind canyon a few times - you can patch the field (data) content of a nested gallery by actually ignoring the galleries themselves and referring to the Items relationship between them, but I have not found a way to refer to user input in a control in the inner gallery - the code is logical and valid syntax should work, but simply does not.
     
    What I have done is used a pop-up with the nested gallery content when the user selects an item in the "main" (now the only) gallery and patch that on a button when it is entered or include a button in the nested gallery to do this. Either way, the data is updated when it is done, instead of at the end.
     
    Please ✅ 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 answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
  • SebS Profile Picture
    4,569 Moderator on at
    Nested gallery
    You’re right — the problem happens because ThisRecord can get confused when used inside nested ForAll loops. In the inner loop, ThisRecord points to the activity record, so it can’t easily access the collaborator from the outer loop. @
     Using As to name each loop (for example, As _G1, As _G2) makes it clear which record you’re working with and avoids mix-ups. Sorry my Bad
  • AN-05111234-0 Profile Picture
    13 on at
    Nested gallery
    Hi @WarrenBelz

    I try your formula but nothing. I think the problem came to the use of double ForAll. When I use one to patch Collaborator it is good but with the second patch didn't functionning. 

    I try something else
     

    // App.OnStart

    ClearCollect(colActivities, Activités);

    // Construire la collection plate (1 ligne par Personne×Activité)

    ClearCollect(

      tempCol,

      ForAll(

        Collaborateurs As G1,

        AddColumns(

          colActivities,

          Colab, G1.Personne,      // name collaborateur

          Date, Datepicker.SelectedDate,    // date 

          Poste, "",                    // value full fill by user

          RowID, G1.Personne & "_" & NomActivite & "_" & Text(Datepicker.SelectedDate,"yyyy-mm-dd")

        )

      )

    );

    ClearCollect(colToEdit, Ungroup(tempCol, Value));


    // In Onchange of dropdown 
    UpdateIf(

        colToEdit,

        (RowID = (Colab & "_" & ThisItem.NomActivite & "_" & Text(Datepicker.SelectedDate, "yyyy-mm-dd"))),

        { Poste: ddl_Valeur.Selected.Value }

    );

    // Save Button

    ForAll(
        colToEdit,
        Patch(
            'Suivi des activités',
            Defaults('Suivi des activités'),
            {
                Collaborateur: Colab,
                Activité: Activit_x00e9_,
                Date: Datepicker.SelectedDate,
                TypePoste: Poste
            }
        )
    );



    When I proceed like this, I can save Collaborator and Actvity but the problem is that the value of the dropdown is not correct. It didn't match with the value enters by user. 

    Any idea
    @WarrenBelz and @SebS
  • WarrenBelz Profile Picture
    152,811 Most Valuable Professional on at
    Nested gallery
    As I noted in my post, it should work, but does not. From what I have tested, you cannot successfully refer to the content of a control in a nested gallery using nested ForAll statements. You may have to look at Patching from inside the nested gallery (then it does not see iteself as nested) with each change made. 
  • SebS Profile Picture
    4,569 Moderator on at
    Nested gallery
    OK the issue is to Achieve perfectly and witchout hassle what you trying to do you need many to many relationship I think


    In Attachment I show You working solution but the issue is It's really time consuming to explain and show how i did it and still i'm not sure if it will fit your requirement

    it's a bit complex :P
     
  • WarrenBelz Profile Picture
    152,811 Most Valuable Professional on at
    Nested gallery
    What @SebS seems to be doing in the movie (please confirm this) is also what I suggested - patch each new item in the nested gallery as it input (rather then trying to do it at the end)
  • SebS Profile Picture
    4,569 Moderator on at
    Nested gallery
    What I did was create a collection that links both tables in a many-to-many relationship, which then produces a flat record that can be patched to the main list. However, this approach can get quite messy — personally, I wouldn’t recommend doing it this way. I’d also avoid nesting everything like that, though it really depends on the app’s context.
  • SebS Profile Picture
    4,569 Moderator on at
    Nested gallery

    I’m not sure how he’s creating the Collaborator or how he plans to add Activities — whether it’s always two, or if the number can vary.

     

    My solution doesn’t depend on how many activities are assigned, but it’s important to understand the start and end logic, as it may later need to support reversing (for example, selecting a person and loading their existing activities back).

     

    Personally, I’d design it with a separate Collaborators table, where Activities are assigned per person for each day of the week. The two galleries would then be linked using Selected.Value.

     

    This way, you’d have a gallery of people, and when you select one, you’d see all their activities, filtered by the date picker. It avoids duplicating records and keeps a clean one-to-many relationship between Collaborator and Activity.

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

Coming soon: forum hierarchy changes

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 314 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 253 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics