Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

How to navigate in an array within Power Automate flow

Posted on February 1, 2023February 1, 2023 by Tom

“I’d like to pick a specific item from an array, what’s the best approach to navigate in there using Power Automate?”


Arrays are a key part of almost every Power Automate flow. It can be an array of SharePoint items or Dataverse rows, array with users inside multiple people picker field, or any other array created by splitting a string. Often you want to process all the items, but in some situations you need just one specific value. How do you navigate in an array? How do you get the value on the first place, last place, or anywhere in between?

Get the first and last item

If you need the first or last item, you can use an expression. This is very often used to avoid loops in a flow – if there’s only one item you don’t need a loop, you can just take the first one and use it directly.

The expression to get the first item is first(…).

first(<array>)

With an example array [“a”, “b”, “c”] the first(…) expression will return “a”.

Power Automate navigate in array

The second expression, this one to get the last item is last(…).

last(<array>)

With an example array [“a”, “b”, “c”] the last(…) expression will return “c”.

Power Automate navigate in array

Get Nth item from an array

If you’re not interested in the first or last item, you can use also indexes in the array for navigation as explained in the JSON navigation article. Adding an index in square brackets will get you the specific item. It starts from 0 (first item) and goes up to length-1 (last item).

<array>[<index>]

As an example, to get the 2nd item use index 1.

Power Automate navigate in array

Getting item on a random index

It gets a lot more complicated if you don’t know the position. If you’re looking for some value but you’re not sure if it’s first, second, third, or anywhere else.

In general you should never get into that situation. It’s not easy to find index of a specific item. Instead of trying to do that you should pre-process the results.

Are you looking for a specific value? Use ‘Filter array’ before accessing the item to remove everything but that item from the array. Apply first(…) on the outcome and you’re done.

Are you looking for the highest/lowest value? Use the sort(…) expression to sort the array first. Move the desired item to the top or to the end of the array and then use first(…) or last(…).

Summary

When you navigate in an array in your Power Automate flow, you must always know what you’re looking for. Is it the first or last item? Use the first(…) or last(…) expression on the array. Is it always Nth item? Use the [index] to get the value. Don’t know the position of the value? Preprocess the array with sorting or filtering that’ll allow you to use one of the expressions or the index.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

  • How to find Excel rows missing in SharePoint list (Power Automate)March 29, 2023
  • Check whether user exists in AAD with Power AutomateMarch 26, 2023
  • How to highlight whole SharePoint row based on calculated dateMarch 22, 2023
  • Why is your Power Automate flow running so slow?March 19, 2023
  • How to add multiple links to the Power Automate approval taskMarch 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes