List variables in Power Automate Desktop

In Power Automate desktop, a list variable stores a set of values or a set of general values that the index and values can access. The Merge list, Shuffle list, Clear list, Reverse list, and other actions are performed on the list.

This Power Automate Desktop tutorial is all about “List variables in Power Automate desktop”. So here we will cover the below List of variable actions.

  • Create List
  • Add an item to the list
  • Remove Duplicate items in this list.
  • Reverse items in the list
  • Remove items from the list
  • Sort items in the List
  • Shuffle items in the List
  • Clear List
  • Find common items in the list
  • Subtract List
  • Merge Lists

Let’s start creating a Power Automate Desktop flow, that will create a List.

Create list variable using Power Automate Desktop

Here we will see how to create a list variable using Power Automate Desktop.

Step 1: Open Power Automate Desktop, click on +New flow -> provide the flow name. Click on Create.

Create list variable using Power Automate Desktop

Step 2: Now we will create a List variable called Product, so, expand the variable section. Then drag and drop the Create new list action to Canvas and provide the below information:

  • Now provide the new list name as Product, then click on Save.
List variables action in Power Automate Desktop

Step 3: Now, to display the product list created successfully we will use the display message action. So, expand the Message box section and then drag and drop the Display Message action to the canvas. Then provide the below information:

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
List variables action in Microsoft Power Automate Desktop

Now save the flow and run the flow; you can see the Message box pop up having the information ‘Product list created successfully’.

List variables action in Microsoft Power Automate Desktop

Add an item to the list in Power Automate Desktop

Here we will see how to add an item to the above Product List in Power Automate List.

As we have already created the Product List in the above section, so now we will add 4 items to this list. Then 4 items are ‘Godrej Tea’, Cadbury Dairy Milk, Tonned Milk, and Tonned Milk.

Expand the variable section, then drag and drop the ‘Add item to list ‘ action to canvas. Then provide the below information:

  • Add item: Provide the item name ‘Godrej Tea’.
  • Into List: Click on the variable icon {x} -> select Product, then click Save.
How to add items to the list in Power Automate Desktop

Similarly, we can add other items to the Product List, after that, we need to display a list of items. So, expand the Message box section and then drag and drop the Display Message action to the canvas. Then provide the below information:

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
 add items to the list variable in Power Automate Desktop

Now save the flow and run the flow; you can see the Message box pop up having the information ‘Product list created successfully’. So, click on ok.

Once items are added to the list, you can see the Message box will open and display all the items in the list.

Power Automate Desktop add items to the list variable

Remove Duplicate items in this list using Power Automate Desktop

Here we will see how to remove duplicate items from the above list in Power Automate Desktop.

The product list contains Godrej Tea, Cadbury Dairy Milk, Tonned Milk, and Tonned Milk. You can see the item ‘Tonned Milk’ are of two times, so we will remove the items, and the list contains: Godrej Tea, Cadbury Dairy Milk, and Tonned Milk.

For this expand the variable section, then drag and drop the Remove duplicate item from list action to canvas. Then provide the below information:

  • List to remove duplicates item from: Click on the variable icon {x}, then select the Product variable, and click on Save.
Power Automate Desktop remove duplicate items from the list variable

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
Microsoft Power Automate Desktop remove duplicate items from the list variable

Now save the flow and run the flow, you can see the Message box pop up having the information ‘Product list created successfully’. So, click on ok.

See also  How to Convert XML to SharePoint List using Power Automate?

Once items are added to the list, the Message box will open and display all the items in the list. Then you can see the duplicate items are removed from the List in Power Automate.

Microsoft Power Automate Desktop remove duplicate items from the list variable actions

Reverse items from the list using Power Automate Desktop

Here we will see how to reverse items from the list using Power Automate Desktop.

As Product List, contains items such as Godrej Tea, Cadbaury Dairy Milk, and Tonned Milk, after reversing the items the result will be Tonned Milk, Cadbaury Dairy Milk, and Godrej Tea.

For this, expand the variable section, then drag and drop the Reverse items from the list action to canvas. Then provide the below information:

  • List to reverse: Click on the variable icon {x} -> select the Product variable, and click on Save.
Microsoft Power Automate Desktop reverse list items from the list variable actions

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
Power Automate Desktop reverse list items from the list variable actions

Now save the flow and run the flow, you can see the Message box popup displays the items that are reversed.

Power Automate Desktop reverse list items from the list variable

Remove items from the list using Power Automate Desktop

Here we will see how to remove a single item from a list using Power Automate Desktop.

As product List contains the items i.e. Tonned Milk, Cadbury Dairy Milk, and Godrej Tea. After removing ‘Tonned Milk’, the items left on the list are Cadbury Dairy Milk and Godrej Tea.

Expand the variable section, then drag and drop the Remove items from list action to canvas. Then provide the below information:

  • Remove the item by: Selecting the value from the dropdown.
  • With the value: Provide the value as Tonned Milk.
  • Click on the variable icon {x} from the list, and select the Product variable. Then click on Save.
Microsoft Power Automate Desktop remove list items from the list variable

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
Microsoft Power Automate Desktop remove list items from the list variable

Now save the flow and run the flow, you can see the Message box popup displays the items by removing Tonned MIlk.

Microsoft Power Automate Desktop remove list items from the list variable

Sort items in the List using Power Automate Desktop

Here we will see how to sort items in the List using Power Automate Desktop.

Example 1: Sort items in the list

As, we have a list called Person which contains names i.e. Alex, Ron, John, and Akon. Then we will use the Sort list action to sort the items. After sorting the items the result will be Akon, Alex, John, and Ron.

Power Automate Desktop sort list items from the list variable

Like a Product list, you can create a Person list and add items to it in Power Automate Desktop as shown in the above screenshot.

Then expand the variable section, and drag and drop the Sort list action to the canvas. Then Provide the below information:

  • List to Sort: Click on the variable icon {x} -> select the Person and click on Save.
How to sort items in list variable in Power Automate Desktop

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
sort items in list variable in Power Automate Desktop

Now save the flow and run the flow, you can see the Message box popup displays the items that is sorted.

sort items in list variable in Microsoft Power Automate Desktop

Example 2: Sort list items based on the Properties

See also  How to Convert String to GUID in Power Automate?

For this, we will take a list of files in the folder, and then based on file name, we will sort the files.

sort items list variable action in Microsoft Power Automate Desktop

Now let’s create a flow in PAD, that will sort the file based on the name.

First, we will get all the files from the folder, so, create a new flow in PAD and then provide the flow name.

Then expand the Folder section under Action, and drag and drop the Get files in folder action to the canvas. Then provide the below information.

  • Folder: Select the folder where files are available.
Power automate desktop sort list items variable

Let’s sort the files based on the names, for this, expand the variable section and then drag and drop the Sort list action to Canvas. Then provide the below information:

  • List to sort: Click on variable icon {x}, select Files, and then click on Save.
  • Enable the ‘Sort by list items properties’ options.
  • The first property to sort by: Provide ‘Name’
  • Sort: select Ascending
Power automate desktop sort list items variable actions

To display the result, we will add the display message action. So, expand the Message box section, then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
Microsoft Power automate desktop sort list items variable actions

Now save the flow and run the flow, you can see the Message box popup displays the files that is sorted by the name.

MS Power automate desktop sort list items variable actions

Shuffle list items in Power Automate Desktop

Here we will see how to shuffle Person list items in Power Automate Desktop.

So, here we will take the above Person list, which contains names i.e. Alex, Ron, John, and Akon, and then shuffle the person names and display it. Every time we will shuffle the list, it will return a random permutation of the list.

For this, expand the variable section, and then drag and drop the Shuffle list action to Canvas. Then provide the below information:

  • List to shuffle: Click on variable icon {x}, select Person, and then click on Save.
MS Power automate desktop shuffle list items variable actions

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
Power automate desktop shuffle list items variable actions

Now save the flow and run the flow, you can see the Message box popup displays the shuffled list items.

Power automate desktop shuffle list items variable

Clear the list in Power Automate Desktop

Here we will see how to clear items from the list in Power Automate Desktop.

Here, we will take the Person list, which contains names i.e. Alex, Ron, John, and Akon. Then we will use the Clear list actions to make the list empty.

For this, expand the variable section, drag and drop the Clear list action to canvas, Then provide the below information:

  • List to clear: Click on variable icon {x} and select Person. Click on Save.
Power automate desktop clear list items variable

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
Microsoft Power automate desktop clear list items variable action

Now save the flow and run the flow, you can see the Message box popup displays the empty list.

MS Power automate desktop clear list items variable action

Find common items in the list using Power Automate Desktop

Here we will see how to find common items in the list using Power Automate Desktop.

Here we will create two lists i.e. Group1Persons and Group2person. The Group1Person contains items such as Alex, Ron, John, Stwart, and Ruby, and Group2person contains items such as Alex, Ruby, Roselin, and Celia. Then we will find common items from the list by using the ‘Find common items in list’ action, it will return Alex, Ruby.

See also  How to Extract substring from text using Power Automate Desktop?

In Power Automate desktop, create a new flow, and provide the flow name. Click on Create.

List variables in Power Automate Desktop

Next, create a list, for this expand the Variable section, then drag and drop the Create a list to canvas. Then provide the below information

Now provide the new list name as Group1Person, then click on Save.

MS Power automate desktop find common list items variable action

Expand the variable section, then drag and drop the ‘Add item to list ‘ action to canvas. Then provide the below information:

  • Add item: Provide the item name ‘Alex’.
  • Into List: Click on the variable icon {x} -> select Group1Person, then click Save.
Power automate desktop find common list items variable action

Similarly, add other items to the list, then the flow will look like below.

Power automate desktop find common list items variable

After that, we will create another list Group2Persons. So similarly, create this list as we have created the above Group1Person list. Then add items to the Group2person list.

MS Power automate desktop find common list items variable

Now we have both the list, we can find the common items from both the lists. So, expand the variable section, then drag and drop the Find common list items action to canvas. Then provide the below information:

  • First List: Click on variable icon {x}, select Group1Person, and click on save.
  • Second List: Click on variable icon {x}, select Group2Person, click on save
find common list items variable in Power automate desktop

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
How to find common list items variable in Power automate desktop

Now save the flow and run the flow, you can see the Message box popup displays the common items in the list.

Microsoft Power automate desktop find common list items variable

Subtract items from the Lists

Here we will how to subtract items from the lists using Power Automate Desktop.

For this, we will take the above lists i.e. Group1Person and Group2person. Then we will subtract both the lists using Subtract list action and get the items from Group1Person, that are not in a Group2Person list.

So, expand the variable section and drag and drop the Subtract item action to the canvas. Then provide the below information:

  • First List: Click on variable icon {x}, select Group1Person, and click on save.
  • Second List: Click on variable icon {x}, select Group2Person, click on save
How to substract list items variable in Power automate desktop

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas.

Then provide the below information:

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
How to substract list items in Power automate desktop

Now save the flow and run the flow, you can see the Message box popup displays the items available in the first list, not in the second list.

How to substract list items in Microsoft Power automate desktop

Merge list in Power Automate Desktop

Here we will see how to merge two lists in Power Automate Desktop.

For this, we will take the above lists i.e. Group1Person and Group2person. Then we will merge both the lists using Merge list action and get all the items from Group1Person and Group2Person lists.

Then expand the Variable section, and drag and drop the Merge list action to the canvas area. Then provide the below information:

  • First List: Click on variable icon {x}, select Group1Person, and click on save.
  • Second List: Click on variable icon {x}, select Group2Person, and click on save.
How to merge list items in Microsoft Power automate desktop

To display the result, we will add the display message action. So, expand the Message box section, and then drag and drop the Display Message action to the canvas. Then provide the below information

  • Message box title: Provide the title like below.
  • Message to display: Provide the message to display like below.
How to merge list items in Power automate desktop

Now save the flow and run the flow, you can see the Message box popup displays the all items in both lists.

merge list items in Power automate desktop

Conclusion

In this Power Automate Desktop tutorial, we saw all about list variables action in Power Automate Desktop.

You may also like:

>