In Power Automate, there are many situations where you need to split a string and retrieve a specific part, such as the first, last, or any specific n-th value. For example, suppose you have a string like this: “123 Main Street, Springfield, IL, 62704.”
Now, you want to extract only the city (Springfield) or the ZIP code (62704), or even just the street name (123 Main Street).
That’s where the split() function becomes useful. You can break the string into parts using a delimiter (like a comma), and then pick the exact item you need.
In this Power Automate tutorial, I will show you:
- Get the First Item from a Split String in Power Automate
- Split a String and Retrieve the Last Value in Power Automate
- Retrieve the N-th Item from a String in Power Automate
Get First Item From a String in Power Automate
Let’s say you’re collecting responses from a Microsoft Form where users enter a list of their skills, separated by commas. For example:
Excel, Power BI, SharePoint, Teams
You want to extract only the first skill from the list (in Excel) and store or display it in another step of your workflow.
Follow the below steps:
- Create an Instant cloud flow (with a manual trigger).
- Add a “Initialize variable” action:
- Name: UserSkills
- Type: String
- Value: Excel, Power BI, SharePoint, Teams

- Add a “Compose” action. In the Inputs field, enter the following expression:
split(variables('UserSkills'), ',')[0]

After that, click Save and then Run it manually. Once it runs successfully, click the compose action.

This expression splits the string by commas and returns the first item (index 0) from the array in Power Automate.
Check Out: Create Multi Agent in Copilot Studio
Get First Item From a String Using first() in Power Automate
Suppose you’re processing job application data submitted through a SharePoint list. One of the columns, Preferred Locations, stores multiple city names as a comma-separated string, like:
New York, Chicago, San Francisco, Seattle
You want to get the first preferred location, which is New York, and use it in an email or condition.
Check the steps below:
- Create or open a flow that’s connected to your SharePoint list.
- Add Initialize variable action and provide the below parameters:
- Name: Skills
- Type: String
- Value: New York, Chicago, San Francisco, Seattle

- Add a Compose action to get the first item. Use the following expression:
first(split(variables('Skills'), ','))

Output:

This method uses the first() function to return the first item from the array produced by the split() function.
Note:
You can also use the take() function to get the first item from a split string in Power Automate: take(split(variables(‘YourString’), ‘,’), 1)
This splits the string into an array, takes the first item, and returns it using the first() function.
Learn: Create Autonomous Agents in Copilot Studio
Split a String and Retrieve Last Value in Power Automate
Suppose you’re receiving filenames from a shared document path like:
Finance/Reports/Quarter3/ExpenseSummary.pdf
You want to split the path and retrieve only the last part, which is the actual filename: ExpenseSummary.pdf
- Create an Instant cloud flow (with a manual trigger).
- Add a Compose and provide the below value:
Finance/Reports/Quarter3/ExpenseSummary.pdf

- Add another compose action and give the following expression:
last(split(outputs('Compose'), '/'))

Once you set up the actions, click Save and then Run the flow. After it runs, open the Run History and check the output of the Compose.

This splits the string by / and uses the last() function to get the final item in the resulting array, which is the file name.
Check Out: Create an Agent Flow Using Designer in Copilot Studio
Get Last Item from a Split String Using Length and Index in Power Automate
You have a SharePoint list where one of the columns stores the full path of a document, like:
Shared Documents/Finance/Reports/Expense2025.pdf
You want to extract only the filename (Expense2025.pdf) from the full path. However, you want to avoid using the last() function and instead calculate the last item manually using the array’s length.
Follow the below steps:
- Open Power Automate and create a new Instant cloud flow.
- Add an Initialize variable action and provide the below parameters:
- Name: FilePath
- Type: String
- Value: Shared Documents/Finance/Reports/Expense2025.pdf

- Add a Compose action. Use the following expression in the Inputs:
split(variables('FilePath'), '/')[sub(length(split(variables('FilePath'), '/')), 1)]

Output:

This method is useful when you can’t or don’t want to use the last() function in Power Automate.
Learn: Create a New Agent Using Microsoft Copilot Studio
Retrieve N-th Item from a String in Power Automate
Let’s say you’re working with a SharePoint list where users enter their project codes as a single comma-separated string:
PRJ001, PRJ002, PRJ003, PRJ004
You want to extract the 3rd item from this string (PRJ003) and use it in your flow, maybe to send a reminder, update a different system, or filter data.
Steps to Retrieve the N-th Item from a String:
- Create a new flow. Add an Initialize variable action and provide the below parameters:
- Name: ProjectCodes
- Type: String
- Value: PRJ001, PRJ002, PRJ003, PRJ004

- Add a Compose action to retrieve the N-th item. Use the following expression to get the third item (index 2):
split(variables('ProjectCodes'), ',')[2]

Output:

You can change the index number to retrieve any item. For example:
- To get the 1st item ->
[0] - To get the 5th item ->
[4]
Always ensure the string contains enough items to prevent errors.
Read: Create an Agent Flow With Natural Language in Copilot Studio
Power Automate: Retrieve the N-th Item from a String Using skip()
You’re storing department codes from a form response in this format:
HR,FIN,IT,OPS,LEGAL
Now you want to extract the 4th item (i.e., OPS) from the list. Instead of using direct indexing, you decide to use the skip() function to make the logic more flexible, especially helpful if you’re working with dynamic positions later.
- Open Power Automate and create a new flow.
- Add a Compose action and provide the below input:
HR, FIN, IT, OPS, LEGAL

- Add a Compose action to extract the n-th item. Use the following expression to retrieve the 4th item (index 3):
first(skip(split(outputs('Compose'), ','), 3))

Output:

This method is excellent when you’re using a dynamic number for the index.
Note:
You can use this method in combination with a variable or expression to skip a dynamic number of items.
first(skip(split(variables(‘Departments’), ‘,’), int(variables(‘IndexToSkip’))))
In this Power Automate tutorial, we learned how to split a string and retrieve specific parts of it, whether it’s the first, last, or any N-th item. These techniques are particularly useful when working with data such as form responses, SharePoint fields, document paths, or any comma- or slash-separated values.
We covered multiple methods using expressions like split(), first(), last(), take(), skip(), and even used length() to calculate positions. Depending on your use case, you can select the method that best suits your workflow.
You may also like:
- Send an Email with Attachments in Power Automate
- Send Email Reminders from a SharePoint List using Power Automate
- Send an Email with Attachments from Local Folder using Power Automate
- Send a Customized email when a new item is created in a SharePoint list using Power Automate

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.