Remove items from a list
In Power Automate Desktop, a variable that can hold multiple values is called a “list”.
This article explains how to remove all or some of the items in list data.
Removing all items (clearing a list)
Section titled “Removing all items (clearing a list)”To remove all the items in a list, you can simply use the “Clear list” action.
Add the sample flow by copying and pasting
Section titled “Add the sample flow by copying and pasting”As a sample, here’s a flow that creates a list with three initial items and then clears it.
Copy the following code and paste it into the Power Automate Desktop flow designer to add the actions.
SET InitializedList TO ['itemA', 'itemB', 'itemC']Variables.ClearList List: InitializedList ClearedList=> InitializedListFor details on defining a list with multiple initial values, see the following page.
Add the action in Power Automate Desktop
Section titled “Add the action in Power Automate Desktop”- In “Search actions”, type “Clear list”.
- Enter the variable name of the list you want to clear, and all the items in that list are removed.
Possible errors
Section titled “Possible errors”This action doesn’t throw any errors, so you don’t need to handle any.
Removing some items
Section titled “Removing some items”To remove only some of the items in a list, use the “Remove item from list” action.
Add the sample flow by copying and pasting
Section titled “Add the sample flow by copying and pasting”As a sample, here’s a flow that creates a list with three initial items and then removes the second one.
Copy the following code and paste it into the Power Automate Desktop flow designer to add the actions.
SET InitializedList TO ['itemA', 'itemB', 'itemC']Variables.RemoveItemFromList.RemoveItemFromListByIndex ItemIndex: 1 List: InitializedList NewList=> InitializedListImplement in Power Automate Desktop
Section titled “Implement in Power Automate Desktop”- In “Search actions”, type “Remove item from list”.
- In “Remove item by”, choose how to specify the item to remove. Select “Index” to remove the nth item, or “Value” to remove items that have a specific value.
- Enter the index of the item to remove (“1” in this sample) or its value, along with the variable name of the list. The matching item is then removed from the list based on the option you chose.
When you specify an index, keep in mind that numbering starts at 0.
For example, to remove the second item stored in a list, specify “1” as the index.
Possible exceptions
Section titled “Possible exceptions”An error occurs if the specified “Index” is outside the range of the list. For example, if the list holds four items, setting the index to “4” or higher causes an error.
If you specify a value instead of an index, an error occurs when that value doesn’t exist in the list.