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

Define a variable name based on the value in another variable

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all,

 

I'm trying to do the following:

1) Get the sub-folders for a specific folder

2) Get a separate list of the files in each sub-folder (For each loop)

3) Perform some subsequent actions based on the contents of the lists

 

Looping through the sub-folders is no issue. However, since the "Get files in folder" action stored the results in a list variable that is defined once, each loop deletes the previous list. So what I would like to achieve is that one list is created per loop.

 

I have tried to achieve that by storing the loop count in a variable and appending that value to the variable name in each loop, thereby creating a separate list for each loop. However, I can't figure out how to define part of the variable name by using a value stored in another variable.

 

Any suggestions?

2021-05-20_11-41-55.png

  • Verified answer
    Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at

    You can't generate variable variable names.

     

    But you CAN put the lists of files into a total list. Just Add item to list.

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Henrik_M : Thanks for the reply! That would work. Too bad it doesn't work to create variable names dynamically, but this solves the current problem.

  • JAWL Profile Picture
    393 on at

    @Anonymous  @Henrik_M and anyone else, can't we put a variable inside a variable? I'm trying to achieve the same objective by using variable %LoopIndex% inside a variable of Column Name in Excel. Meaning my end result should be: CurrentItem[1], CurrentItem[2], CurrentItem[3], etc.

     

    Below is invalid expression in Power Automate Desktop as there is variable inside a variable:

    JAWL_0-1658376772943.png

     

  • VJR Profile Picture
    7,635 on at

    Please check if CurrentItem supports indexing else you will get an error.

    You can check this by using a hard coded number like %CurrentItem[0]%

     

    But to answer your question about variable inside variable it is done as follows

    %VariableName[IndexNo]%

     

    You will get more info here.

    https://docs.microsoft.com/en-us/power-automate/desktop-flows/variable-data-types

     

  • JAWL Profile Picture
    393 on at

    Hi @VJR , appreciate your reply. But do you set IndexNo as variable and then increase by 1 for looping purpose?

     

    So my logics is that we should put the IndexNo as dynamic variable as per below, am I wrong?

    %VariableName[%IndexNo%]%

  • VJR Profile Picture
    7,635 on at

    Hi @JAWL 

    For the first part of the question it will depend on what you want to do.

     

    For the second you cannot use multiple percent sign within one another as %VariableName[%IndexNo%]%

    You will need to refer it as below.

    %VariableName[IndexNo]%

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
Mohsin Ali Profile Picture

Mohsin Ali 426

#2
11manish Profile Picture

11manish 308 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 159

Last 30 days Overall leaderboard