web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / first() function does ...
Power Automate
Answered

first() function does not work as intended

(0) ShareShare
ReportReport
Posted on by 17

Hi, I need help with something. Sorry for the basic question.

 

I'm trying to process an array, extracting values from a string separated by delimiter.

What my flow is doing is:

1. A new form is submitted

2. The flow is triggered. Get response detail

3. Get an item from the form which has multiple lines of string. Example:

 

formdata:

RE - 100/120/1.03
YE - 2581/2871/1.03
BE - 0.152/0.572/1.03

forms1.png

 

 

 

 

4. Split this data into an array with 3 items, using split(formdata, newline Constant). Assign result in variable Lists: IR End to End (Earth)

*newline Constant is a variable with the value decodeUriComponent('%0A')

*formdata is one of the data in the form response. See attachment for actual code

So far I get the expected output which is ["RE - 100/120/1.03","YE - 2581/2871/1.03","BE - 0.152/0.572/1.03"]

 

5. Obtain the first element in the array, using first(variables('Lists: IR End to End (Earth)'))

 

The expected output is:

RE - 100/120/1.03

 

But instead I get the output :

[

 

forms2.png

 

Can anybody help me on why is this happening? Thanks in advance.

*I've even set this up with another variable not from the form, but I get the same result.

 

forms3.png

Categories:
I have the same question (0)
  • creativeopinion Profile Picture
    10,504 Moderator on at

    @fusop27 To split on a new line use a Compose action to store a line break. I cover how to do that in this section of my YT Tutorial: 7 Functions You Need to Know | ️Expression Essentials: Part 1

     

    In the full tutorial I cover 7 functions you need to know when getting started with expressions.

    1️⃣ empty()

    2️⃣ coalesce()

    3️⃣ equals()

    4️⃣ if()

    5️⃣ concat()

    6️⃣ length()

    7️⃣ split()

     

    I cover how to use these functions in expressions and I’ll also cover common mistakes when it comes to writing expressions and show you a few tips and tricks along the way.

     

    As a beginner or even an intermediate flow builder—expressions can seem a bit complex at first, I’m going to try to simplify it for you. If you want to level up your flows by writing expressions—keep watching!

     

    IN THIS VIDEO:

     What is an Expression?

     What is a Function?

     What Does Wrapping a Function Mean?

     How Do I Insert an Expression?

     How to Use a Compose action

     How to Navigate the Expression Builder with Arrow Keys

     How to use the Expression Tooltip

     Common Mistakes When Writing Expressions

     How to differentiate a null from an empty string

     How to Get Dynamic Content When it’s Not Listed

     How to Use a Get Item Action to Verify Dynamic Content Output

     How to Convert Strings to Lower Case

     How to Troubleshoot the if() Function

     

    Hope this helps!

    If I helped you solve your problem—please mark my post as a solution .
    Consider giving me a 👍 if you liked my response!

    👉 Level up your Power Automate skills by checking out my tutorials on YouTube
    👉 Tips and Tricks on TikTok and Instagram
  • fusop27 Profile Picture
    17 on at

    Using Compose to split actually helps, now I don't have to use decodeURIcomponent() anymore.

     

    But this doesn't answer my question though. I was wondering why the first() function didn't produce the expected output? Even though I think I have created a proper array data after using split(). See point number 5 in my post. Thanks!

  • Verified answer
    fusop27 Profile Picture
    17 on at

    Nevermind, I think I found what's the problem. 

     

    Using Compose to split and using Variables to split produces two different results 

     

    Variables will force the output into a single line string

    ["RE - 100/120/1.03","YE - 2581/2871/1.03","BE - 0.152/0.572/1.03"]. 

    This is the wrong array format

     

    Compose will format the output into array format with multiple lines separated by comma

    [
      "RE - 100/120/1.03",
      "YE - 2581/2871/1.03",
      "BE - 0.152/0.572/1.03"
    ]
    This is the correct array format
     
    Thanks for the help
     
    Screenshot 1: Comparison of output between Compose and Variable
     
    solution1.png
     
    Screenshot 2: Behavior when using first() expression on Compose output compared to using it on Variables output.
    The first() expression will read the first element in the array of Compose output.
    The first() expression will read the first character in the string of Variables output.
    solution2.png
  • Verified answer
    creativeopinion Profile Picture
    10,504 Moderator on at

    @fusop27 Although using a variable doesn't seem to be necessary in your case, you need to ensure that you are selecting the correct type of variable. The reason your variable wasn't working as expect is you were using a string variable. 

     

    To output an array, you need to ensure you select array as the type when working with arrays. 

    creativeopinion_0-1717220217175.png

    Personally, I prefer to avoid initializing and setting variables unless the flow requires it. I use Compose actions in most of my flows.

     

    Hope this helps!

    If I helped you solve your problem—please mark my post as a solution .
    Consider giving me a 👍 if you liked my response!

    👉 Level up your Power Automate skills by checking out my tutorials on YouTube
    👉 Tips and Tricks on TikTok and Instagram
  • fusop27 Profile Picture
    17 on at

    I did not see the Array type, I'm blind it seems.

     

    Thanks for the help again! Originally, I needed to use it as a variable for value processing reasons for the next module in my flow. I guess I have to keep learning. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
trice602 Profile Picture

trice602 237 Super User 2026 Season 1

#2
David_MA Profile Picture

David_MA 173 Super User 2026 Season 1

#3
Kalathiya Profile Picture

Kalathiya 95 Super User 2026 Season 1

Last 30 days Overall leaderboard