cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Paul112
New Member

How to use ForAll() inside ForAll()

Hello all,
I would like to know how to use ForAll() function inside another ForAll().
Inside ForAll() function, we can use ThisRecord property to retrieve selected record values.
It seems to be allowed to nest second level ForAll() function, but when we do it, ThisRecord property retrieve only last ForAll() level. So, my questions are
- Is it really allowed to nest ForAll() function?
- how to retrieve first level ForAll() values inside second ForAll() level?
If it is not allowed to nest ForAll() function, which formula (or tips) should be used to deliver same result? (meaning Loop insinde another loop)

Thank's

1 ACCEPTED SOLUTION

Accepted Solutions

Thank you @CNT and @RandyHayes to your reactivity.
It is really appreciated !


I'm using tables on each ForAll() level :  first ForAll() will give parameters to the filter used to the second ForAll().

Thank you !

View solution in original post

5 REPLIES 5
CNT
Community Champion
Community Champion

@Paul112  Use As for the Outer lever and refer the outer level using that. ForAll(firstLoop As varFirstLoop ......

RandyHayes
Super User III
Super User III

@Paul112 

Keep in mind that a ForAll is not a For/Loop.  A ForAll is a function that returns a table based on iterations over another table.  So, if you are looking to do what you are doing to try and make a ForAll into a ForLoop, your challenges are ahead with the concept of a for/loop inside of a for/loop because again...ForAll is a table function.  Can they be nested...sure, if you need a table within a table, it is perfectly fine.  

As for referring to tables - PowerApps as has As statement that can be used to provide a named reference to your table (i.e. the ForAll).  

As for ThisRecord - ThisRecord refers to the closes table operation function.  So, ThisRecord inside of a ForAll refers to the current iteration record of the ForAll.  If you have, let's say, a Filter inside of the ForAll to Filter another table to include in your table record of the ForAll, then ThisRecord inside of the Filter would refer to the Filter record.  Best to use the As statement to be clear on what you are referring to.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you @CNT and @RandyHayes to your reactivity.
It is really appreciated !


I'm using tables on each ForAll() level :  first ForAll() will give parameters to the filter used to the second ForAll().

Thank you !

View solution in original post

@Paul112 

Sounds good.  If you get stuck, feel free to post back your formula and I'd be happy to troubleshoot and correct it.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I am trying to do something similar.. I have 2 items in gallery3 and a few modifiers that are different for each gallery item.  The patch is overwriting both item 1 and 2 from the gallery with the modifiers only for item 2 instead of the correct respective modifiers (modifiers for item 1 to item 1). This is my formula: 

 

ForAll(Gallery3.AllItems As yomom,ForAll(LookUp(fdcs559,fdcId=LookUp('Food Nicknames',fghfh=yomom[@Ingredient],fdcId),foodPortions[@modifier]) As hmm,Patch(units7,LookUp(units7,Value=yomom.Ingredient),{Unit2: RenameColumns(Split(Concatenate(Concat(LookUp(units7,Value = yomom[@Ingredient]).Unit2,Unit,"#"),"#",hmm.modifier),"#"),"Result","Unit")})));

 

Please help, thanks!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,274)