...

Get First Value From Array In Power Automate

In Power automate there may be times where you need to loop through a series of records to get a specific value, but what if you don’t want to loop through all the records and you in fact only need the first record.

The Wrong way to do it

We see a lot of people get the first or last record by using variables and looping though lots of records when they only need the first record. This can also be time consuming especially when looking through hundreds of records.

 

The Right Way

There are a couple of ways we can get the first last value, let’s start with the first value. one way is to use the array order to get the first record in the array. If we first add the value we want into a compose this will automatically create an ‘Apply To Each’ loop for us. We need this to start with so we can get the values we want.
 

From the apply to each we need the ‘value’ which will look something like below

 

  outputs('Get_items')?['body/value']  

 

The next part we want is the value of the item

  items('Apply_to_each')?['Title']  

 

We can see above we are getting the ‘Title’ value from them apply to each. As we only want to first item in the array we can combine these together to only get the first item, we can add ‘[0]’ inside between the two to only get the first item in the array. If we wanted the 2nd item in the array we could use ‘[2]’ and so on. 

 

  outputs('Get_items')?['body/value']?[0]?['Title']  

 

We could also use the expression ‘first’

  first(outputs('Get_items')?['body/value'])?['Title']  

The result:

 

Like this post? Why not share it!

LinkedIn
WhatsApp
Facebook
Reddit
X
Email

View Our Other Articles

Get In Touch

Let’s talk. Send us a message, and we’ll help you explore the best Power Platform solution for your business

We can turn your mondain tasks into effective workflows, saving you and your business time and money

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.