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 / ForAll inside a ForAll...
Power Apps
Unanswered

ForAll inside a ForAll that is inside a Collect

(0) ShareShare
ReportReport
Posted on by 14

I have 2 ListBoxes, I'm trying to create a collection with all possible combinations of those lists. The problem in the formula is shown in the second ForAll, when you write it the SelectedItems option is not there, I tried also creating different collections and using them but it seems that it just doesn't work. This is the code I used in the Button:
Note: my powerapps is in Spanish, so there is no error in the semicolons and since comas changed to semicolons, semicolons changed to double semicollons

Collect(
Prueba;
ForAll(
ListBox1.SelectedItems;
{
varGrupoRamo: Value; // Capture the current item from ListBox1
Correo: User().Email;
TiempoEmpleado: 0;
id: 0;
// Inner ForAll loop for ListBox1_2
ForAll(
ListBox1_2.SelectedItems;
{
GrupoRamo: varGrupoRamo; // Use the captured value from ListBox1
ProcesoSV: Value; // Assuming Value is the property you want from ListBox1_2
Correo: User().Email;
TiempoEmpleado: 0;
id: 0
}
)
}
)
)

Categories:
I have the same question (0)
  • BCBuizer Profile Picture
    22,505 Super User 2025 Season 2 on at

    Hi @Sroldan ,

     

    Edit: What is it exactly you are trying to do with the second ForAll loop? I see in the first one you are defining a record, but there's no key defined before the second ForAll.

  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    hey @Sroldan 

     

    As already mentioned its not very clear what you are intending to do so this is just a guessing.

    You can try something like this:

     

    Clear(Prueba); // Ensure Prueba is empty before adding items
    Clear(ColIntermediate); // Clear intermediate collection first
    
    // First loop over ListBox1
    ForAll(
     ListBox1.SelectedItems;
     Collect(
     ColIntermediate;
     // Second loop over ListBox2 for each item in ListBox1
     ForAll(
     ListBox1_2.SelectedItems;
     {
     GrupoRamo: varGrupoRamo; // Use the captured value from ListBox1
     ProcesoSV: Value; // Assuming Value is the property you want from ListBox1_2
     Correo: User().Email;
     TiempoEmpleado: 0;
     id: 0
     }
     )
     )
    );
    
    // Now move the combined data from ColIntermediate to Prueba
    Collect(Prueba, ColIntermediate);
    

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Sroldan Profile Picture
    14 on at

    @mmbr1606 and @BCBuizer in the first place, thanks for answering. 

     

    What I'm trying to do is create a collection with all the possible combinations of both lists. I already solved this problem if I wanted to do it only for one of them:

    Collect( Prueba; ForAll( ListBox1.SelectedItems; { GrupoRamo: Value; Correo: User().Email; TiempoEmpleado:0; id: 0 } ) )

    So if I was doing it like in python it would be:

    for i in ListBox1:

        GrupoRamo=i

        ...

        ...

     

    But I want to do it for both of them, so it would be like this

    for i in ListBox1:

        for j in ListBox1_2:

            GrupoRamo: i

            rocesoSV:j

            Correo: User().Email

            TiempoEmpleado:0

            id: 0

     

    Not Sure if this is enough to clear what I would like to do

  • Verified answer
    BCBuizer Profile Picture
    22,505 Super User 2025 Season 2 on at

    Hi @Sroldan ,

     

    I think the below should do the trick for you then:

    Clear(Prueba);;
    ForAll(
    	ListBox1.SelectedItems As _GrupoRamo;
    	ForAll(
    		ListBox1_2.SelectedItems As _ProcesoSV;
    		Collect(
    			Pruebo;
    				{
    				GrupoRamo: _GrupoRamo.Value;
    				ProcesoSV: _ProcesoSV.Value;
    				Correo: User().Email;
    				TiempoEmpleado: 0;
    				id: 0
    			}
    		)
    	)
    )

    After running this formula, the Pruebo collection should contain all possible combinations of the selected items in both listboxes.

  • Sroldan Profile Picture
    14 on at

    Thank you so much @BCBuizer, that is true, it did it for me. So if anyone else reads this at any moment, my main error when I was trying, before asking, was using the Collect function before both ForAll functions and also helps a lot using the aliases (As). 

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard