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

For each index - incerement variable: how to get index?

Hi,

 

I guess I would like to do something similar as described here: https://powerusers.microsoft.com/t5/Building-Flows/Can-I-get-index-number-in-apply-to-each/m-p/46543...

 

 

I have an array, here as an example a very simple one and I do a for each over this array.

I would like (or should have) the index of the for each. No clue why the first array value has 3 as incremented variable. It seams the for each are not in order of the array, can that be?

 

How do I get the real/correct for each index (here in this example it would be "1")?

SNAG-0006.png

 

Thanks,

Stefan

1 ACCEPTED SOLUTION

Accepted Solutions

@cgru3eejc2 

 

Good catch. I was under wrong impression that you did not enable Concurrency. Good to see you the issue is resolved.

 

Regards

Krishna Rachakonda

If this reply helped you to solve the issue, please mark the post as Accepted SolutionMarking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone.

View solution in original post

5 REPLIES 5
Solution Sage
Solution Sage

Hi @cgru3eejc2 ,

 

Are you using Loop inside loop (for each) to iterate over each array and each item inside that array ? If so you have to clear out the value at the first step before going to inner for each loop. This way you get the right value inside that inner loop.

 

Thanks

@cgru3eejc2 

 

You cannot increment variable value while setting it. 

 

Place a compose action before Set Variable. Insert the expression for increment of the variable in the compose action. 

 

Now, Set Variable to the output of the above Compose action.

 

Regards

Krishna Rachakonda

If this reply helped you to solve the issue, please mark the post as Accepted SolutionMarking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone.
Advocate IV
Advocate IV

Hi @ManishJain  and @rsaikrishna 

 

Thanks for your messages.

It's the only "loop" (for each). The increment on it's own counts up fine, so this is also not the problem.

 

I guess I found it - the for each is using parallelism (of course)...

I now changed the "Concurrency Control" in the for each settings to 1 and with that the for each index is equal to the variable which increments with each for each item loop.

Concurrency Control
By default, "For each" iterations run at the same time, or in parallel. To change the default limit, turn on this control, and select a limit. To run sequentially, select 1 as the limit.
 
Not sure if there is solution WITH using parallel running for each AND having the "correct" index run number.
 
Thanks all.
Stefan

Hi @cgru3eejc2 ,

 

If you have used concurrency control you have go with @rsaikrishna  method. 

 

If it resolves your issue please mark the solution as accepted.

 

Thanks

@cgru3eejc2 

 

Good catch. I was under wrong impression that you did not enable Concurrency. Good to see you the issue is resolved.

 

Regards

Krishna Rachakonda

If this reply helped you to solve the issue, please mark the post as Accepted SolutionMarking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone.

View solution in original post

Helpful resources

Announcements
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Users online (8,820)