cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Change Name to Initials

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!

4 REPLIES 4
Highlighted
Dual Super User
Dual Super User

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


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Solution Sage
Solution Sage

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
 
Highlighted
Frequent Visitor

Re: Change Name to Initials

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

Highlighted
Community Support
Community Support

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.

Helpful resources

Announcements
firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (8,625)