cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
digiservice
Advocate II
Advocate II

Increment a value in a column within a ForAll loop

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?

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

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 Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Carsten_Growth
Power Apps
Power Apps

See this example

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

@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."

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 🙂 

 

 

v-xida-msft
Community Support
Community Support

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 Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

@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!

This works perfectly thank you @v-xida-msft 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

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.

Top Solution Authors
Top Kudoed Authors
Users online (3,052)