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 III
Dual Super User III

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!



Super User II
Super User II

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
 
Did I answer your question? Please consider to mark my post as a solution to help others.
Proud to be a Flownaut!
Highlighted
Frequent Visitor

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

Highlighted

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

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