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

Set variable function in Power Automate?

Is there a "set" type function within Power Automate? Can't seem to find one. A set action exists, but attempting to avoid an action as this will run within a nested apply to each loop within an if condition action, and evaluating a condition action is very slow in Power Automate. Some performance improvements can be found using the expression builder to code the condition within loops instead.

 

Attempting to work within the limitations of Power Automate given that the if expression must have an else parameter set.

 

Trying to replicate the following, which is simple in most languages, but extremely difficult in Power Automate:

 

if condition is true:

    then set variable1 to value

 

In Power Automate, since an "else" param is required, set a dummy variable with a null:

if(equals(variables('variable1'), true), set(variables(variable1), 'value'), set(variables('dummy'), null))

 

Does a set function exist?

5 REPLIES 5
ScottShearer
Super User
Super User

@MPEng 

There is no expression in Power Automate that allows you to set the value of a variable.  You need to use one of the variable actions such as Set Variable.  

So, in your case, you'll want to use a condition and then a Set Variable action.  Note that you can use expressions in your condition.

image.pngimage.png

 

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
MPEng
Advocate I
Advocate I

@ScottShearer ,

 

Thanks for the response. That's exactly what I was afraid of. My flow is currently designed to execute in the manner that you describe above, but looping through 400+ array elements, then looping through a secondary nested array with 1-15 elements and evaluating multiple conditions to set a variable is very slow. Doing it the method above causes the processing time to be greater than 2x.

@MPEng 

Any chance that you can use a Filter Array action or other filters to limit the number of elements to loop through?

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
MPEng
Advocate I
Advocate I

@ScottShearer, thanks for the recommendation. Unfortunately, the list of items are already filtered down. It's the data set that needs to be processed..

@MPEng 

Understood.  I don't know if the structure of your Flow will permit it, but if you can use Compose actions rather than variables, you might see some improvement in performance.  Also, try going to settings for your loops and setting concurrency to On and stepping up up the degree of parallelism.  Note that doing so may wreak havoc on variables used in the loop.

My apologies if you already thought of this....

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,335)