Skip to main content

Notifications

Community site session details

Community site session details

Session Id : j1XLcDu7hwdAocqfH81if3
Power Apps - Building Power Apps
Answered

Increment a value in a column within a ForAll loop

Like (0) ShareShare
ReportReport
Posted on 3 Apr 2020 12:01:11 by 76

I am unsure how I would achieve this so hoping for some guidance.

 

I am uploading a local collection to a sharepoint list, that looks something like this:

ForAll(
    MyCollection,
      If(
           MyVariable = false And MyColumn = "New",
           Patch(
                 MySharePointList,
                 Defaults(MySharePointList),
                      {
                        Title: MyTitle,
                        Reference: Reference
                       }
                    )
        )
);

I want to append a number to the Reference column sequentially.

 

So if there are 3 items in the ForAll Loop the outputs would be:

Reference1
Reference2

Reference3 

 

And so on.

What is the best way to achieve this? I would prefer to do this in the upload as this is when we know categorically they final amount of rows that will be uploaded and therefore the sequential numbers that need applying?

  • FU Microsoft Profile Picture
    112 on 23 Sep 2022 at 16:37:26
    Re: Increment a value in a column within a ForAll loop

    Doesn't work for me when updating records via Patch. Strange...

  • digiservice Profile Picture
    76 on 14 Apr 2020 at 15:02:59
    Re: Increment a value in a column within a ForAll loop

    This works perfectly thank you @v-xida-msft 

  • Community Power Platform Member Profile Picture
    on 06 Apr 2020 at 23:12:25
    Re: Increment a value in a column within a ForAll loop

    @v-xida-msft 

    That's a really handy way to add a Counter into a ForAll() loop, I haven't seen that method before. Thanks for sharing!

  • Verified answer
    v-xida-msft Profile Picture
    on 06 Apr 2020 at 08:52:28
    Re: Increment a value in a column within a ForAll loop

    Hi @digiservice ,

    Based on the needs that you mentioned, I think a collection could achieve your needs.

     

    Please consider take a try with the following formula:

    Clear(Counter);
    ForAll(
     MyCollection,
     If(
     MyVariable = false And MyColumn = "New",
     Collect(Counter, 1); // Add formula here
     Patch(
     MySharePointList,
     Defaults(MySharePointList),
     {
     Title: MyTitle,
     Reference: Reference & CountRows(Counter) // Modify formula here
     }
     )
     )
    );

     

    please take a try with above solution, check if the issue is solved.

     

    Best regards,

  • Community Power Platform Member Profile Picture
    on 03 Apr 2020 at 23:32:38
    Re: Increment a value in a column within a ForAll loop

    I'm just following along here to see what happens with this because I was building an answer last night - before I fell asleep lol. I've built a solution that works using @timl solution posted by @Carsten_Growth but I'd like to also see what others can produce as well to compare 🙂 

     

     

  • mdevaney Profile Picture
    29,987 Super User 2025 Season 1 on 03 Apr 2020 at 16:36:49
    Re: Increment a value in a column within a ForAll loop

    @Carsten_Growth 
    I recognize the code you supplied as a post from the blog of @timl.

    Link to blog post: http://powerappsguide.com/blog/post/generating-row-numbers


    It looks like @digiservice is conditionally patching information to the datasource based on status of a record.  Anyway to combine the code you supplied with what the original poster showed?

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • Carsten_Growth Profile Picture
    on 03 Apr 2020 at 16:08:19
    Re: Increment a value in a column within a ForAll loop

    See this example

    Clear(colNumberedInvoices);
    ForAll(Invoices, 
     Collect(colNumberedInvoices,
     Last(FirstN(AddColumns(Invoices,
     "RowNumber",
     CountRows(colNumberedInvoices)+1
     ), 
     CountRows(colNumberedInvoices)+1
     )
     ) 
     )
    )

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 85 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 54

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 42 Super User 2025 Season 1

Overall leaderboard
Loading started