cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
altafr
Frequent Visitor

Using an increment within ForALL

Seemingly simple requirement - want to go through a table looking for  a certain ID and then tag a field within the table with values "01" ," 02", "03" based on how many rows. 

 

So first i filtered all rows required in a collection 

ClearCollect(myrows, Filter (mytable, Field = mycondition));

 

The used a forall 

 

ForAll (

myrows,

Patch(

mytable,

mytable.ID = myrows.ID,

{myfield: Text(Index,"00")},

))

 

Now how do i increment the Index so the next record gets patched with 02 in the forall? 

 

alternatively any other way to approach this problem. any advice appreciated. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @altafr ,

Do you want to auto-increment the Index value within your ForAll formula?

 

Based on the needs that you mentioned, if you want to auto-increment the Index value within your ForAll formula, I afraid that there is no direct way to achieve your needs.

 

As an solution, I think a collection could achieve your needs. Please consider modify your formula as below:

Clear(TempCollection);
ForAll (
        myrows,
        Collect(TempCollection, 1);
        Patch(
              mytable,
              LookUp(mytable, ID = myrows[@ID]),
              {
                myfield: Text(CountRows(TempCollection),"00")
              }
         )
)

 

Please consider take a try with above solution, then 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

2 REPLIES 2
RandyHayes
Super User III
Super User III

@altafr 

 

Give this a try...

 

Clear(myrows);
ForAll(Filter(mytable, Field = mycondition),
    Collect(myrows,
            {myID: ID,
             myIndex: CountRows(myrows)
            }
    )
);

 

Then for your patch:

ForAll (myrows,
   UpdateIf(mytable,
            ID = myID,
           {myfield: Text(myIndex,"00")}
   )
)

 

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!
v-xida-msft
Community Support
Community Support

Hi @altafr ,

Do you want to auto-increment the Index value within your ForAll formula?

 

Based on the needs that you mentioned, if you want to auto-increment the Index value within your ForAll formula, I afraid that there is no direct way to achieve your needs.

 

As an solution, I think a collection could achieve your needs. Please consider modify your formula as below:

Clear(TempCollection);
ForAll (
        myrows,
        Collect(TempCollection, 1);
        Patch(
              mytable,
              LookUp(mytable, ID = myrows[@ID]),
              {
                myfield: Text(CountRows(TempCollection),"00")
              }
         )
)

 

Please consider take a try with above solution, then 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

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.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,427)