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 Automate / Iterate a variable name
Power Automate
Answered

Iterate a variable name

(0) ShareShare
ReportReport
Posted on by 108

 If I'm looping through steps and I want to merge two lists into a separate list name that iterates based on %LoopIndex%, how would I do that? I want a separate merged list to be output for each iteration for easy merging into a complete list. I've tried adding lists instead, but it results in all data for the list added being added to a single row within the merged table.  I'd like to avoid manipulating individual rows of data since they're already properly formatted.

 

Example of problem:

 

Run 1: %List_A% merges with %List_B% into %List_C%

Run 2: %List_A% merges with %List_B% into %List_C%, not merging with %List_C% from Run 1 , but overwriting data from List C in the first run.  Again, adding to a list results in all data from a list being placed into a single row of the complete list.

What I'd like to do:

 

Run 1: %List_A% merges with %List_B% into %List_C[LoopIndex]% (List_C1)

Merge %List_C[LoopIndex]% into %List_Complete%

 

Run 2: %List_A% merges with %List_B% into %List_C[LoopIndex]% (List_C2)
Merge %List_C[LoopIndex]% into %List_Complete%

 

Run 3: %List_A% merges with %List_B% into %List_C[LoopIndex]% (List_C3)
Merge %List_C[LoopIndex]% into %List_Complete%

 

If the variable was numerical, it would be easy.

 

The issue is that merging List A + B into List C doesn't merge with a pre-existing List C, it overwrites it.  If merging two lists into another list merged rather than overwrote, I wouldn't have an issue.

I appreciate any advice!

  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    Important question:  do you need access to %List_C1% once %LoopIndex2% starts?

     

    If not, then I think you have the right logic:

    Create %List_Complete% (outside of loop)

     

    inside the loop:

    Create %List_C%
    merge %List_A% to %List_B% in %List_C%
    ‘Do whatever you need with List C for this run

    add %List _C% to %List_Complete% (or merge, whichever you need, you should be able to merge List_C and List_Complete into List_Complete.)

    Delete %List_C%

    End Loop

     

    Your current run List_C will always be current and List_Complete will have all the List_C data

     

    On the other question posed, which would be relevant if you need to access the separate loop run list Cs after it exits the loop, you cannot create a variable out of a variable (for example, you can’t ‘Create List %List_C_%LoopIndex%%’ inside of a loop to create multiple List Cs. You can however, write your lists to Excel to read them back later.  This is the easiest thing I have found to do.

    I also built a flow that creates variables for this purpose, so my main flow calls a flow which creates a flow creating the variables and then runs the flow passing the needed variables to an environment variable which is then called from ‘get environment variable’ on the main flow, but that is very complex.  Writing and reading to/from Excel is much easier. 

  • Slavnyy_Avtomat Profile Picture
    108 on at

    I don't need access to %List_C% once it's data have been merged into the %List_Complete%.  That being said, I think you nailed it here: Excel will be much simpler for my purposes.  I appreciate your help, Michael; you're one of the most consistently helpful posters on the forum!

  • Slavnyy_Avtomat Profile Picture
    108 on at

    It just clicked -- I was overthinking it.  The solution for what I was looking for is what you'd said more or less.

    Instead of merging A and B into C, forget C entirely and merge A and B separately with Complete and into Complete:

    Merge %List_A% with %List_Complete% into %ListComplete%
    Merge %List_B% with %List_Complete% into %ListComplete%

    Perfect -- you nailed it, Michael.

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Nice, glad you found it.  I like to help, because I also learn.  I did not know that a merge by default overwrote an existing list, so knowing to include the previous list if you do not want the list overwritten is important.  Thanks for the heads up.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 249 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 198

#3
David_MA Profile Picture

David_MA 197 Super User 2026 Season 2

Last 30 days Overall leaderboard