Everything you need to know about variables – Microsoft Power Automate Desktop tutorial

If you are new to Microsoft Power Automate Desktop and you do not have a programming background, a huge obstacle you will face is to fully understand various terms that you will encounter frequently. A very common term used in Microsoft Power Automate Desktop is “variables”.  To ensure a smooth process while developing your flow, it is vital to have a full understanding of how to handle variables.

While automating your tasks on Microsoft Power Automate Desktop, you will see yourself using the same information over and over again for different actions. For example, sometimes, you might want to store customers’ data, like the name and email that you have retrieved, and process them later in your flow.  

What are variables?

In short, variables allow you to store data/information from one action to use in another action when you need it later. Variables are like tags that you attach to data with a descriptive name of your choice, which you can then easily refer to when needed. 

Variables are like storage containers that store and save information while a flow is running. This information can be of any type, such as numbers, text, dates, files, folders and text. 

To use variables in actions, the name of your variables has to be enclosed in percentage(%) characters. For instance, you have a variable called ClientName, the proper way to express it as a variable is: %ClientName%. If the % sign is excluded, the application will read the value as a hardcoded content and not as a variable.

Create and Use variables

Microsoft Power Automate Desktop will create your variables automatically that the deployed actions require. This is to avoid the creation of any nonessential variables. However, you are able to create the variables manually and disable the automatically produced variables. 

So how does the application automatically produce variables, and how do you identify them? Microsoft Power Automate Desktop will automatically produce variables that hold the results of the action whenever you add a new action to the main workspace. Over here in blue text is the variable that is automatically produced.

To change the name of the variable to something easier for you to identify, click on the variable and change as desired. 

If you know that you will not be using the variable produced by a certain action, you can choose to disable the automatic production of that variable. This will allow your variables pane to look more organized and less convoluted. 

To disable the production of variables you don’t need, simply click on the toggle switch icon to disable that particular variable. When the text changes to grey, it means that you have successfully disabled the variable.

Once you have created your variables, you may need to use the information stored in the variable as input in other deployed actions in your flow. To do this, click on the {x} icon next to the field you would like to input the variable and pick the desired variable.

Note:  You have the option to use existing variables as outputs in other actions, but Power Automate Desktop will overwrite the previous content. This may cause confusion, so we don’t recommend it. 

Variables pane

The variables pane is located on the right side of the flow designer. It displays all the variables that have been created, along with additional information and controls to manage all of your variables.

There are two different forms of variables located in the variables pane to allow you to manage all the variables in your flow: input/output variables and flow variables.

Input/Output variables – With this, you can move data from other platforms to the Microsoft Power Automate Desktop or vice versa. Automation options are endless with this inbuilt feature. This is just a brief definition of input/output variables. We will go more in depth in future articles. 

Flow variables – List of all the variables that are available in the particular flow. This includes all the variables in the main and subflows. It does not include variables from other flows in your console. 

To display additional information on the variables, you can just double-click on the variable name. 

You can use the variable pane to see all the available properties of your variables. Properties contain parts of the information stored in the variable or extra attributes describing the variables.

While you are debugging your flows after facing errors, you can check each variable’s current value through the variables pane. Seeing how the flow changes the variables’ contents allows you to locate the source of error and correct it accordingly. 

To view more information or rename variables in the variables pane, just simply right click on the name of the variable or the vertical Ellipsis. You will be given the options to View, rename or Find Usage.

View – View Variable value

Rename – To change the name of a variable

Find Usage – Additional information will be displayed regarding that particular variable. You will be able to know which subflow it belongs to, which line(s) it belongs to and more information about the action it belongs to. When you double click on one of the results, it will direct you to the specific line that the variable is used in. 

If you have developed a very complicated flow with many variables, you can filter the variables based on Text value, Datetime, List of general values, General value, Numeric value. This allows you to be more efficient.

Data types

Microsoft Power Automate Desktop will categorise your variables to a specific variable data type based on the content.

There are over 40 data types on this application, but the more common data types are numbers, time and boolean. 

Quick tip: If you are new to Microsoft Power Automate Desktop, it is advisable to use different variables instead of converting variables type as you have to constantly keep track of which content you overwrite. This is to avoid any mistakes and confusion along the way. 

Some of the built-in data types have properties that are related to the value stored in the variables.

With these properties, you will be able to obtain information about the variables without the need for additional actions or complicated conversions.

This information can describe the content of the variable or be a part of a multi-component content. For example, you can get the day part of a date or the size of a list with files.

To access the value of a property, you can use the following notation: %VariableName.PropertyName%.

For example, if the flow contains a list of files called Files, you can get the number of the stored files using the expression: %Files.Count%.

If you don’t know what properties are available for a particular variable and what the correct notation is, you can click on {x}, find your variable, and click the arrow beside it, as shown in the picture below.

Advanced data types

Advanced data types need specific treatment and handling. In this article, we will only go through two advanced data types: Lists and data tables.

Lists – A list is a collection of items that must be of the same data type. Use a list when you want to store and collate many information of the same data type. For example, you can create a list of text values, numbers, files, etc.

To create a new list, go to variables, click on the arrow beside it, and look for the action Create new list. A simpler way to do this is to search Create new list action on the search bar of the action pane. Then, add the action Create new list to the main workspace. 

Another way that is slightly different is to create lists through actions that generate lists as output, for instance Get files in folder action that returns a files list.

If you want to find a specific item in the list, you can use the following notation: %VariableName[ItemNumber]%.

For example, you can rename the first folder of the previously displayed folder list using this notation. Keep in mind that the ItemNumber should be 0 for the first item of the list. 

Data Tables – Use data tables if you want to store data in a table form. It is similar to excel—a data table has both rows and columns.

Each item stored in it can be retrieved through its unique row and column number. Consider data tables as lists that have other lists as items.

There is no direct way to create a data table, but you can create data tables through the Read from Excel and the Execute SQL statement actions.

If you want to find a specific data table item, you can use this notation: %VariableName[RowNumber][ColumnNumber]%.

For example, you can save Apple’s price inside a new variable (which we named %ApplesPrice%) using the following action. 

Note:  Keep in mind that the RowNumber and the ColumnNumber should be 0 for the first item.

Variable Manipulation

Earlier in the video, we learned that it is important to enclose your variables with % so that the app can identify them as variables. Some of you might wonder, what if I want to use the percentage sign as a simple character in a hardcoded text? All you have to do is to use double percentage signs like this: %%.

Hardcoded text – You might want to use hardcoded text values. To do so, use quotes to enclose your text values. Microsoft Power Automate Desktop will identify any value between quote characters as a text value and not a variable name. 

Variable Names – You might want to use multiple variables in an expression. To do that, simply add their names to the expression without further notation.

Basic Arithmetic – If you want to use mathematical operations, you can use plus (+), subtract (-), multiply (*)  and divide (/). You can use the addition operator to join strings. However, this does not include arithmetic operations with numerical values and variables. Adding numbers and text strings in the same expression will convert the numbers into text and join them with the other text strings.

Comparisons – Besides arithmetic operators, you can also make comparisons using the following relational operators:

Logical Operators – In many flows, you might need to check if a value meets some particular standards. To check conditions and implement more complex logic in a single expression, you can use the logical operators. The supported operators are AND and OR.

Parentheses  While creating complex expressions, you might want to prioritize some specific parts of them. To change an operators’ priority, use parentheses. Power Automate Desktop handles parentheses the same way as algebra and programming languages.

Conclusion

While developing your flows on Microsoft Power Automate Desktop, you will always be in contact with variables. Hence, it is important for you to understand what variables are and how to handle them when developing your flows. Just remember that variables allows you to store and reuse data and to use the variables pane to control or make changes to your variables.

Tags: Microsoft Power Automate Desktop, Robotic Process Automation, Console, Flow designer 

Learning resources: https://docs.microsoft.com/en-us/learn/modules/pad-variables/

Software Version: Microsoft Power Automate Desktop 2.7.49.21099