November 17, 2024

Arrays are part of the building blocks of Power Automate. We can get arrays from many actions like the SharePoint “Get Items” action, for example. But there are a lot of times that we only want the first element of the array. So that’s where the Power Automate “first “function comes into play.

Let’s see how to use it efficiently.

Usage

It follows a simple pattern.

  1. Array to parse

Let’s start with a simple example:

createArray('Manuel','T','Gomes')
first(<array>)

will return 

'Manuel'

How about if the array is empty?

createArray()
first(<array>)
The “first” function will return an empty result and won’t break, so you can be sure to use it even if the array is empty.
I recommend using the null and length function so that you’re sure that the data is valid.

We’re using the createArray function to generate a test array, but you’ll probably use another action in your case.

Finally, let’s check if it’s a string. We can do the following:

first('Manuel,T,Gomes')

will return

'M'

Here you can consider the string as an array of characters. The Power Automate “first “function will return the first character of the array. The same happens if there are spaces in a string.

first('Manuel T Gomes')

will return

'M"

Please don’t use this to break comma-separated strings. The split function is better at doing this. You can also check my “How to parse a CSV file” article and template for more details.

Limitations

I could not find any limitations for this function, but please let me know if you do.

Recommendations:

Here are some things to keep in mind.

Don’t nest

There’s no real reason to do it, but if you find yourself in a situation where you have nested the first functions in a formula, you should review it and make everything more straightforward.

Sources:

Microsoft’s first Function Reference

Back to the Power Automate Function Reference.

Photo by Possessed Photography on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

Leave a Reply

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

Mastodon