Skip to content

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.

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=> InitializedList

For details on defining a list with multiple initial values, see the following page.

  1. In “Search actions”, type “Clear list”.
  2. Enter the variable name of the list you want to clear, and all the items in that list are removed.

This action doesn’t throw any errors, so you don’t need to handle any.

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=> InitializedList
  1. In “Search actions”, type “Remove item from list”.
  2. 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.
  3. 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.

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.