← Al Davies, 250 High Street

How to get the first N items of an array in Power Automate

Use take() in a Compose action. For example, take(variables('MyArray'), 3) returns the first three items as a new array. To drop the first items instead, use skip(variables('MyArray'), 3).

What does take() do in Power Automate?

take() returns a new array that holds the first items of the original. It needs two values: the collection and the number of items to keep. The format is take(collection, count).

The original array does not change. The function also works on text, where it returns the first characters.

How do you get the first 5 items from a list?

If the array has fewer than five items, you get all of them. Test this case before you rely on the result.

  1. Add a Compose action after the step that returns your array.
  2. Open the input and switch to the Expression tab.
  3. Enter take(outputs('Get_items')?['body/value'], 5), using the name of your own step.
  4. Choose Add, then save and run the flow.
  5. Read the Compose output in run history.

What does skip() do?

skip() does the opposite of take(). It removes the first items and returns the rest. The expression skip(createArray('A','B','C','D'), 2) returns C and D.

A common use is to drop a header row from data that you read from a file.

How do you get items from the middle of an array?

Combine the two functions. To keep items 3 to 5, write take(skip(variables('MyArray'), 2), 3). The inner skip() removes the first two items. The outer take() keeps the next three.

To get the largest or newest items, sort first. The sort guide shows how. Then use take() on the sorted result.

How do you remove the last item of an array?

No single function does this. Use take() with a calculated count: take(variables('MyArray'), sub(length(variables('MyArray')), 1)).

For how length() counts items, read how to count items in an array.

When should you use filter instead?

take() and skip() work by position. They do not look at the values. To keep items that match a rule, such as Status equals Open, use the Filter array action.

You can use both. Filter first, then take the first few results.

How do you run a loop on only the first N items?

Put the take() expression in the input of the Apply to each action. The loop then runs only on those items.

To pull out one item and not a group, see how to get the first item with first().

FAQ

What is the syntax of take() in Power Automate?

take(collection, count). It returns a new array with the first count items.

How do I skip the first row in Power Automate?

Use skip(array, 1). It returns every item after the first.

How do I get items 3 to 5 of an array?

Write take(skip(array, 2), 3). Skip the first two items, then keep the next three.

What happens if take() asks for more items than the array has?

You get the items that exist. Test with a short array to confirm.

Sources