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
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: