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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Increment in a ForAll(...
Power Apps
Answered

Increment in a ForAll() with a condition

(0) ShareShare
ReportReport
Posted on by 3,340

Shane young did a good job of explaining how to use Sequence() for incrementing in a ForAll() (Click for Shane's Video) .  However, I need to increment inside my ForAll() if a condition is met.  Thus, Sequence is a no-go.  Since Set() and UpdateContext() arent happy inside ForAll(), is there another option?

 

Just to start discussion, this is the theory of what I want to do.  However, it wont work because UpdateContext() isnt valid.

 

 

With({_FData:FilteredData},
 ForAll(_FData,Patch(FilteredData,LookUp(FilteredData,Index=ThisRecord.Index),{GroupIndex:GpIndx});If(LookUp(FilteredData,Index=Index+1).Valve_Type<>ThisRecord.Valve_Type,UpdateContext({GpIndx:GpIndx+1})))

 

 

Categories:
I have the same question (0)
  • Verified answer
    PaulD1 Profile Picture
    2,914 on at

    Although you cannot do a Set or UpdateContext in a ForAll, I believe you can patch to a collection, so you can update a specific record in an existing collection and refer back to it.

    Note that ForAll is not guaranteed to process records in order so do be careful if that could be an issue in your scenario.

  • Verified answer
    Adrian_Celis Profile Picture
    1,652 Moderator on at

    Hi @martinav 

    @PaulD1 is right. What I would do is create a temp Collection and then increment the value there.

    Sample:

    ClearCollect(collTemp,{Value:0});
    
    With({_FData:FilteredData},
     ForAll(_FData,Patch(FilteredData,LookUp(FilteredData,Index=ThisRecord.Index),{GroupIndex:GpIndx});
    If(LookUp(FilteredData,Index=Index+1).Valve_Type<>ThisRecord.Valve_Type,Patch(collTemp,First(collTemp),{Value:Value+1})));
    
    UpdateContext({varResult:First(collTemp).Value});

    varResult should be your total incremented.

    Addt'l notes :  You can use With inside a ForAll but I still can't find a way to transfer a With variable to a context or global variable.

     

  • martinav Profile Picture
    3,340 on at

    @Adrian_Celis 

     

    Yes! Patch!  I should have thought of that.. I mean, I'm doing that already.  Thanks for the reminder!

     

    ROd

  • martinav Profile Picture
    3,340 on at

    @PaulD1 

     

    THats an interesting point about records not going in order.  I will watch my output.  Since this is a one time thing.  I can explicity lookup each time, and override the order.   GOod point!


    Thanks

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 541

#2
WarrenBelz Profile Picture

WarrenBelz 434 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 289

Last 30 days Overall leaderboard