The Power Automate Last function returns the last item of a given collection or the last character of a given string.
To find the first element or character, take a look at the Power Automate first function.
In this article, I’ll introduce you to the last function and will provide a step-by-step guide on how to use the function in a Microsoft flow.
Power Automate Last Function
Power Automate Last Function
Return the last element from of an array or string.
Syntax
last('<collection>')
last([<collection>])
Input parameters
- collection (mandatory): The collection/string of which the last element/character should be returned.
Return value
- Returns the last element/character of the given collection/string.
Power Automate Last Expression Example
last(createArray(7,8,9))
=> 9
last('abc')
=> 'c'
How To Use The Power Automate Last Function
Follow the steps to use the Power Automate Last function in a flow.
-
Create a new flow with trigger ‘Manually trigger a flow’
New flow
-
Add a new step by clicking on ‘+ New step’
Add a new step
-
Search for ‘initialize’ and click on ‘Initialize variable’
Add Initialize variable action
-
Setup Initialize variable: 1) Provide a name, 2) select type Array, 3) Set value to ‘[7,8,9]’
Setup variable
-
Add a compose step by searching for ‘compose’ and clicking on ‘Compose’
Add Compose action
-
Setup compose action: 1) click into Inputs (popup appears), 2) click on ‘Expressions’, 3) set expression to ‘last(variables(‘myArray’))’ 4) click on ‘OK’
Setup last expression in Power Automate
-
Save and do a test run
Result test run – Power Automate last function example