Split String & Retrieve Specific Item in Power Automate [First, Last, N-th]

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:

  1. Create an Instant cloud flow (with a manual trigger).
  2. Add a “Initialize variable” action:
    • Name: UserSkills
    • Type: String
    • Value: Excel, Power BI, SharePoint, Teams
Power Automate String Split & Retrieve
  1. Add a “Compose” action. In the Inputs field, enter the following expression:
split(variables('UserSkills'), ',')[0]
Extract Specific Value from String Power Automate

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

Power Automate Get First Item After Split

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:

  1. Create or open a flow that’s connected to your SharePoint list.
  2. Add Initialize variable action and provide the below parameters:
    • Name: Skills
    • Type: String
    • Value: New York, Chicago, San Francisco, Seattle
Power Automate Dynamic String Parsing
  1. Add a Compose action to get the first item. Use the following expression:
first(split(variables('Skills'), ','))
Get first Item from Split String Power Automate

Output:

Power Automate String Split Techniques

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

  1. Create an Instant cloud flow (with a manual trigger).
  2. Add a Compose and provide the below value:
Finance/Reports/Quarter3/ExpenseSummary.pdf
Get Last Item from Split String Power Automate
  1. Add another compose action and give the following expression:
last(split(outputs('Compose'), '/'))
Get value between last en second last delimiter from string in Power Automate

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.

Power Automate last function

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:

  1. Open Power Automate and create a new Instant cloud flow.
  2. Add an Initialize variable action and provide the below parameters:
    • Name: FilePath
    • Type: String
    • Value: Shared Documents/Finance/Reports/Expense2025.pdf
Usage of First & Last Function in Power Automate
  1. Add a Compose action. Use the following expression in the Inputs:
split(variables('FilePath'), '/')[sub(length(split(variables('FilePath'), '/')), 1)]
How To Split String And Get Last Element In in Power Autoamte

Output:

Get the Last Item from a Split String Using Length and Index in Power Automate

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:

  1. Create a new flow. Add an Initialize variable action and provide the below parameters:
    • Name: ProjectCodes
    • Type: String
    • Value: PRJ001, PRJ002, PRJ003, PRJ004
Retrieve First, Last, N-th Item Power Automate
  1. 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]
Get N-th Item from Array Power Automate

Output:

get nth item from array power automate

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.

  1. Open Power Automate and create a new flow.
  2. Add a Compose action and provide the below input:
HR, FIN, IT, OPS, LEGAL
4 Ways to Get a Value from an Array in Power Automate
  1. 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))
Get Nth Item from the result of Split function in Power Automate

Output:

Power Automate Retrieve the N-th Item from a String Using skip()

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:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App