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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Return First word in a...
Power Automate
Answered

Return First word in a string

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi I would like to build an expression in Flow that returns the first word in a string.  Basically I want to get someone's first name from a user's Display name. I know I can use the action Get Profile to get someones first name instead of the Display Name but we use that field as user's Legal name and it doesn't always make sense.

 

Example User's Display Name in AD is Bob Smith but in AD we have his First name as Robert and last name as Smith.

 

When a flow triggers an email to him I would like the email to start with "Hi Bob" instead of "Hi Robert"

 

Thanks in Advance

Categories:
  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    I have made a test on my side and please take a try with the following workaround:

    • Add a proper trigger, here I use Flow Button trigger.
    • Add a "Get user profile (V1)" action, User (UPN) field set to email address or UPN of the user.
    • Add a "Compose" action, Inputs set to following formula:
    • indexOf(body('Get_user_profile_(V1)')?['DisplayName'],' ')
      Add a "Compose 2" action, Inputs set to following formula:
    substring(body('Get_user_profile_(V1)')?['DisplayName'],0,outputs('Compose'))

     

    The Display Name content on my side as below:10.JPG

    Image reference:11.JPG

    The flow works successfully as below:12.JPG

     

    Best regards,

    Kris

     

  • takolota1 Profile Picture
    4,980 Moderator on at

    Answer Addendum

     

    Thank you Kris for the original work-around with the Compose steps. Unfortunately, even the Compose steps didn't work when I tried using one for a "contains(string, ' ')".

     

    Something was still wrong with the space ' '. If anyone runs into the same problem, I got it to work by using three apostrophes ''' '''. So "contains(string, ''' ''')".

     

     

  • takolota1 Profile Picture
    4,980 Moderator on at

    I've also made something for anyone trying to get a first name or first string from unclean data.

    This returns most first names in proper format (examples: “jOhN  SMITH” to “John” or “McJohnson SMITH” to “Mcjohnson” or “   jane  ” to “Jane”)

     

    With Compose Steps to avoid invalid space ‘ ’ entry in expressions

    Compose_2:

    int(indexOf(trim([Full Name Dynamic Content]), ' ')), 1)))

     

    Compose_3:

    contains(trim([Full Name Dynamic Content]), ''' ''')

     

    Copy here ↓ & enter dynamic content with names wherever it says "[Full Name Dynamic Content]".

    if(outputs('Compose_3'), trim(concat(substring(toupper(trim([Full Name Dynamic Content])), 0, 1), substring(toLower(trim([Full Name Dynamic Content])), 1, sub(outputs('Compose_2'), 1)))), trim(concat(substring(toupper(trim([Full Name Dynamic Content])), 0, 1), substring(toLower(trim([Full Name Dynamic Content])), 1))))

     

     

    Example in an automatic response email that is sent out if the email field in a form has a value. There is also a back-up automatic email if something fails with the first name expression.

    Auto Emails with First Name.png

     

    Use of the clean first name formula.

    Auto Emails with First Name2.png

  • majofe Profile Picture
    6 on at

    I found that 

    first(split(body('Get_user_profile_(V2)')?['displayName'],' '))

     can accomplish this in one step.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 249 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 202

#3
David_MA Profile Picture

David_MA 180 Super User 2026 Season 2

Last 30 days Overall leaderboard