web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Call different variabl...
Power Automate
Unanswered

Call different variables with dynamic name change

(1) ShareShare
ReportReport
Posted on by 2

Apologies if this has been asked before, but I can't seem to find the answer online, although I may just be searching for the wrong things.

 

TL;DR: How do you input expressions into the variables() function, for example in loops where the variable needed changes on each iteration?

 

Due to the way my business is run, we need to keep track of time spent on each client who we work for and I'm trying to create a flow to automate this process. The time tracker data for the last week is put into an excel table of which the flow performs an 'Apply to each' process and for each time log matching a client 'x' it increments 2 variables "'x' Hours! and "'x' Minutes" by the hours/minutes value in the time log, where 'x' is a client's name. The aim of this is to then add rows to another excel table with columns named "Client", "Hours" and "Minutes" so we can see the total time spent on each client for that week. Hopefully I've explained my process so far clear enough for people to understand.

 

Unfortunately we have quite a large list of clients and so adding an 'Add row to an excel table' action for each one would not only be quite tedious and make my flow overly long but would be prone to errors and would it make it difficult to add or remove clients. Therefore, I decided to make an array of clients and have an Apply to each loop run through it adding a row to an excel table each time adding the client name with their respective hours and minutes. However, if I try to add a variable using an expression so that the variable name changes on each loop, and so I get a different variable on each loop, I'm not allowed to save my flow. This is due to the variable() function not accepting anything but a string as a parameter even if the parameter I'm providing (e.g. items('Apply_to_each')['Hours'] or item().Hours or concat(items('Apply_to_each'),' Hours') ) evaluates to a string.

 

I can't really attach a screenshot of my flow as it has a lot of client names so hopefully my explanation is all that is needed.

Does anyone know why the variables() function won't accept other expressions and does anyone know a workaround for what I'm trying to do?

 

Thanks in advance for any help anyone can provide.

 

Kyle

Categories:
I have the same question (0)
  • PieterVeenstra Profile Picture
    on at

    It looks like you are looking for variable varibale names. This doesn't exist in flow at least not wihtin the variables connector.

     

    The best way to get this done is by using the select action.

     

    The slect action will let you create an array of a data structure.

     

    So imagine you have the following array:

     

    "Client Name", "Hours1", "Hours2"

    "Client 1", "1", "2"

    "Client 2", "3", "4"

     

    The firsit column is the cleint name and the 2nd and 3rd column is number of hours and you now want to create totals of column 2 and 3 giving you:

     

    "Client Name", "Total Hours"

    "Client 1", "3"

    "Client 2", "7"

     

    With the select action you could create something like this. The client value would need to be set to the cleint from your source data and the total would be an expressions where you add the numbers:

     

    selecttotal.PNG

     

     

  • GabrielStJohn Profile Picture
    on at

    Hello, @kyle95!

     

    Thank you for posting on the Flow Community Forum! Have you had an opportunity to apply @Pieter_Veenstra‘s recommendation to adapt your Flow? If yes, and you find that solution to be satisfactory, please go ahead and click “Accept as Solution” so that this thread will be marked for other users to easily identify!


    Thank you for being an active member of the Flow Community!

     

    -Gabriel
    Flow Community Manager

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard