Power Automate - Quick Tip - First Expression

Power Automate - Quick Tip - First Expression

Have you come across a case where you need to List Rows with a filter applied and expect to only receive a single record returned? When you try to access attributes of the single record, the action is wrapped in an Apply To Each loop even though only a single record is returned. The First expression can help us out here.

Here is what our flow would look like without using the First expression.

I perform a List Rows step to retrieve the accountid and name, limiting my List Rows action to returning only a single record. Following the branch on the right side, we can see the Compose action gets wrapped in an Apply To Each loop. This feels unnecessary, so let's take a look at the First expression.

Following the branch on the left, we can see the First expression in use. Notice how much easier this is to read and removes the unnecessary actions.

Here is the sample expression:

first(outputs('List_rows')?['body/value'])?['name']

This expression ensures only the very first record is selected from the rows returned in our List Rows step and gives us the Account Name of that record- this would work even if we didn't limit the List Rows step to the top 1. We can use this expression to get any attribute returned in the List Rows step.

Compare the two branches here, the flow becomes more legible and more efficient by using the method on the left side branch.

Have you come across this when creating new Power Automate flows? How have you tackled problems like this?