Introduction
In Power Platform, for certain business scenarios we must extract first, and last characters of a given string or First and Last items present in an array. The first And Last function can be used in power automate to achieve this functionality.
Step 1
Login to the required Power Apps environment using URL make.powerapps.com by providing username and password and click on Flows on the left-hand side as shown in the below figure.
![Usage of First & Last Function in Power Automate]()
Step 2
After Step 1, Click on New Flow and select instant cloud flow and provide the trigger as Manually trigger a flow and click on Create as shown in the below figure.
![Usage of First & Last Function in Power Automate]()
Step 3
After Step 2, name the flow as First And Last Function and take a parallel branch and one side of branch take an initialize variable and name it as Initialize variable - Array- Set List Of Contacts and provide values
Name: ContactsList
Type: Array
Value: ["Venkata","Polisetty","Subbarao"]
as shown in the below figure.
![Usage of First & Last Function in Power Automate]()
Step 4
After Step 3, to the other side of parallel branch take another initialize variable and name it as Initialize variable - String - User Name and provide values
Name: UserName
Type: String
Value: Venkata
as shown in the below figure.
![Usage of First & Last Function in Power Automate]()
Step 5
After Step 4, now under Initialize variable - Array- Set List Of Contacts take a compose action and name it as First Function Array and provide the inputs with first function which returns the first element in the array or string passed with the following syntax
first(collection: array|string)
as
Inputs : first(variables('ContactsList'))
as shown in the below figure.
![Usage of First & Last Function in Power Automate]()
Step 6
After Step 5, now under Initialize variable - String - User Name take a compose action and name it as First Function on String User Name and provide the inputs as
Inputs : first(variables('UserName'))
as shown in the below figure.
![Usage of First & Last Function in Power Automate]()
Step 7
After Step 6, under First Function Array action take new action and name it as Last Function Array and provide inputs as
Inputs : last(variables('ContactsList'))
![Usage of First & Last Function in Power Automate]()
Step 8
After Step 7, under First Function on String User Name action take new action and name it as Last Function on String User Name and provide inputs as
Inputs : last(variables('UserName'))
![Usage of First & Last Function in Power Automate]()
Step 9
After Step 8, save and test the flow and observe results as shown in the below figure.
![Usage of First & Last Function in Power Automate]()
Note
- Make sure to save and run the flow whenever you try expressions.
- Make sure to provide input array in proper acceptable format of string array.
- Also use double quotes for the elements in the array.
Conclusion
In this way, we can use the first and last function in power automate to achieve customer functionality.