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

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Change Name to Initials
Power Automate
Unanswered

Change Name to Initials

(0) ShareShare
ReportReport
Posted on by 13

I am using MS Forms to collect data and Power Automate to send that data to an Excel Workbook.  In the form I am collecting names as one of the fields.  I would like the flow to convert their name to their initials and write the initials to Excel.  There are only about six different names being input into the Form.  Example: John Smith = JS, Amy Johnson = AJ.  I tried using an IF expression but I cannot get that to work.

 

Thanks!

Categories:
I have the same question (0)
  • efialttes Profile Picture
    14,756 on at
    Re: Change Name to Initials
    Hi!
    Let's assume you have "John Smith" stored in a variable called 'inputName'
    If so you can convert by means of the following sequence:
    Add an 'Initialize variable' name 'outputName', type string no value.
    Add an 'Apply toEach' action block, assign as its input the following expression:
    split(variables('inputName'),' '))
    Inside the appy to each add 'Append to string' action block, name 'outputName' assign as its value the following expression:
    first(item())
    Finally, you can add a compose action block out of the 'Apply to eac' and assign as its input the following expression:
    join(variable('outputName'),'')

    There are other possible approaches, so instead an Apply to each you can use a Select action block and assign the following expression as its input
    split(variables('inputName'),' '))
    then assign the following expression as the mapping formula
    first(item())
    ...and finally get the expected result by means of a Compose action block, assigning as its inpit the following expression:
    join(body('Select'),'')

    Hope this helps
  • fchopo Profile Picture
    8,003 Moderator on at
    Re: Change Name to Initials

    Hi @rnunley 

    I have used the following flow with some expressions to solve what you want to achieve:

    forms.png

    In this case, the field  body('Get_response_details')?['r9723f014ffc146debd7eeca108b84ad0'] is the Forms field with the Name.

    Here are the expressions used on each step:

    1) Get the blank position between the first name and the last name: 

    indexOf(body('Get_response_details')?['r9723f014ffc146debd7eeca108b84ad0'],' ')
    2) Get the First Initial:
    substring(substring(body('Get_response_details')?['r9723f014ffc146debd7eeca108b84ad0'],0,variables('BlankPosition')),0,1)
    3) Get the LastName length:
    sub(sub(length(body('Get_response_details')?['r9723f014ffc146debd7eeca108b84ad0']),variables('BlankPosition')),1)
    4) Get the last name Initial:
    substring(substring(body('Get_response_details')?['r9723f014ffc146debd7eeca108b84ad0'],add(variables('BlankPosition'),1),variables('LastNameLength')),0,1)
     
    Hope it helps!
    Ferran
     
  • rnunley Profile Picture
    13 on at
    Re: Change Name to Initials

    I got it working.  I used the "Switch" step in Power Automate along with a variable.

  • alrezac Profile Picture
    on at
    Re: Change Name to Initials

    Hi,

     

    That's great that you got it working! Remember to set as resolved for however helped you.

     

    Regards,

     

    Alex

     

    -------

     

    Community Support Team _ Alex Rezac
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • wlyttle Profile Picture
    58 on at
    Re: Change Name to Initials

    I tried your solution but I'm having issues. At the Apply to each I'm getting an error - The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression 'split(variables('@{variables('inputName')}'),' '))' is of type 'String'. The result must be a valid array.

    wlyttle_0-1643832701598.png

     

     

  • wlyttle Profile Picture
    58 on at
    Re: Change Name to Initials

    I followed your steps but I still cannot get it to work.  Says I need an array not string. 

  • KvB1 Profile Picture
    1,596 on at
    Re: Change Name to Initials

    You can use this much more elegantly:

     

    concat(substring(split(variables('inputName'),' ')[0],0,1),substring(split(variables('inputName'),' ')[1],0,1))
  • KvB1 Profile Picture
    1,596 on at
    Re: Change Name to Initials

    Also this assumes that the name only consists of 2 words, sepparated by a single space, so its important to adhere to that format, or else youd have to make things dynamic

  • wlyttle Profile Picture
    58 on at
    Re: Change Name to Initials

    Thank you for taking the time to post. I'm not sure on how to use your solution. If you could be so kind what are the steps needed to make this work? I want to use the Displayname from the user.

  • KvB1 Profile Picture
    1,596 on at
    Re: Change Name to Initials

    Oh right, so this is a person/group field in SharePoint?

     

    It would be good to know where the data is coming from that you want to use, and what kind of format it has

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard