Power Automate  

How to Use Variables in Power Automate Desktop

Hello Developers! In this blog, I’ll walk you through one of the most fundamental concepts in Power Automate Desktop (PAD): variables. If you are just starting with PAD or automation in general, this will be a great starting point to understand how data is stored, passed, and manipulated inside your desktop flows.

What are Variables in Power Automate Desktop?

Let me put it in simple terms: variables are like containers where you can store data temporarily while your automation is running. You can store numbers, text, dates, lists, and even complex data types, such as custom objects.

Think of them like tiffin boxes, you can store different types of food (data) in each box (variable), carry them with you (use in other steps), and even change the contents later.

Why Do We Need Variables?

Let’s say you are automating a task to read an Excel file, filter some data, and send a summary email. In this case, you will need to.

  • Store the file path (Text variable).
  • Capture the filtered rows (DataTable variable).
  • Keep count of rows (Numeric variable).
  • Prepare dynamic email content (Text variable).

Without variables, this would be like cooking without utensils – messy and impossible to manage!

How to Create Variables in Power Automate Desktop?

PAD makes it very easy to create and use variables. There are two common ways to create variables:

Method 1. Automatically by Actions

This is the most common way. Many actions in PAD automatically generate output variables.

Example

When you use the 'Read from Excel worksheet' action, it will provide an output, such as ExcelData, which you can use in the following steps.

You can rename it if you want to something like dtEmployeeData for better readability.

Pro Tip: Always give meaningful names to your variables. It’ll help when your flows grow bigger.

Method 2. Manually Using “Set Variable” Action

If you want to create and assign a value to a variable manually, follow these steps:

Steps

  • Search for “Set Variable” in the Actions pane.
    Set Variable
  • Drag and drop it into your flow.
  • It is ready to use.

Types of Variables in PAD

PAD supports many types of variables depending on your use case. Some of the commonly used ones.

Variable Type Example
Text "Hello, World"
Number 100, 3.14>
Boolean True, False
DateTime 05/06/2025 12:30 PM
List ["Gowtham", "Raj", "Anand"]
DataTable A full table from Excel
File/Folder Paths to files or folders

As you become more advanced, you’ll use loops and conditions to manipulate these variable values.

Example Use Case

Let’s build a small scenario.

Goal: Show a greeting message to the user based on the current time.

Steps

Step 1. Get Current Time.

  • Search for “Get current date and time” in the Actions pane.
  • Drag it into your flow.
  • It will output to a variable, such as CurrentDateTime.

You can rename it to something like currentTime

Step 2. Convert datetime to text.

  • Action: Convert datetime to text
  • Input: %currentTime%
  • Format: Custom
  • Custom format

Step 3. Extract the Hour using Substring.

  • Action: Get subtext
  • Text to extract from: %currentTimeText%
  • Start index: 11 (Because the hour starts at the 11th character in the string)
  • Length: 2
  • Output: hourText

Example: From 06/04/2025 09:45:00, this gives "09".

Substring

Step 4. Convert to Number.

  • Action: Convert text to a number
  • Input: %hourText%
  • Output: TextAsNumber

Convert to Number

Step 5. Use If Condition

Condition: %TextAsNumber% < 12

Condition

  • If true → Set variable greetingText = "Good Morning"
  • Else → Set variable greetingText = "Good Evening"

Step 6. Display Greeting

  • Action: Display message
  • Message to display: %greetingText%
    Display Greeting

Bonus Tips

  • Clear variables if not needed later, to avoid memory issues.
  • Use the “Display Message” or Log to File action to debug variable values during flow execution.
  • Avoid variable names like test1, var123. Be descriptive: invoiceTotal, userEmail, startDate.

Final Thoughts

In the world of automation, variables are your best friends. They help your brain remember, make decisions, repeat actions, and respond. Once you master variables, you’re already halfway through mastering Power Automate Desktop!

So next time when you build a flow, give a slight nod to your hardworking variables.

Do you have any doubts or real-world automation problems? Drop a comment or message me on C# Corner. Let’s learn and grow together.

Happy Automating!