Power Automate split() Function: Split a String Into an Array (With Examples)

If I look back at the flows I’ve built over the past few years, a surprising number of them start by breaking a piece of text apart. A Microsoft Forms question returns several choices in one comma-separated answer. A SharePoint column holds email addresses separated by semicolons. An email body needs to be processed line by line, or a file name needs its extension checked before the flow decides what to do with it.

All of these jobs come down to the same function: split(). It’s simple once you’ve used it a couple of times, but there are a few traps, especially with line breaks and empty values, that trip up almost everyone at first.

Quick answer: split('text', 'delimiter') returns an array of the pieces between each delimiter. For example, split('Apps,Automate,BI', ',') returns ["Apps","Automate","BI"]. Get one piece with first(), last() or an index such as [1], and split on a new line with decodeUriComponent('%0A').

In this tutorial, I’ll explain the syntax and then walk through the splits I use most often, each with the exact expression, so you can copy it straight into your own flow.

split() syntax

The function takes two values: the text you want to split, and the character or characters to split it on.

split('<text>', '<delimiter>')
ParameterWhat to enter
textThe string to split, usually dynamic content, a variable or a Compose output
delimiterThe character to split on, in single quotes, such as ',', ';' or ' '

The result is always an array, even if the delimiter doesn’t appear in the text (you then get an array with one item). One behaviour to remember is that empty pieces are kept, so split('a,,b', ',') returns ["a","","b"]. You’ll find the details in the split() reference on Microsoft Learn. Power Automate uses the same expression language as Azure Logic Apps, and text values always go in single quotes, never double quotes.

Example 1: Split a string by a word or character

Let’s start with the simplest case. Create an instant cloud flow with the Manually trigger a flow trigger, so you can test it with one click. Then add an Initialize variable action, set Name to Text and Type to String, and enter the text you want to split in Value.

Initialize variable with the text to split in Power Automate

Next, add a Compose action and enter this expression in Inputs. Here I’m splitting on the word and, to show that the delimiter doesn’t have to be a single character:

split(variables('Text'), 'and')
Compose action with the split expression in Power Automate

Save and test the flow. The Compose output is an array containing the text before and after each and:

split() output as an array in Power Automate

Example 2: Split by comma, semicolon or space

In real flows, the delimiter is usually a comma, a semicolon or a space. Only the second value of the expression changes:

split(variables('Names'), ',')
split(variables('Emails'), ';')
split(variables('FullName'), ' ')

For example, splitting a full name on a space gives you the first name and the last name as separate items:

Compose action splitting a variable by space in Power Automate
Power Automate split string by space output

Watch out for values separated by a comma and a space, such as Amy Jackson, David Henry. Splitting on the comma alone leaves a space at the start of every piece after the first, which can break comparisons later. You can either split on both characters, split(variables('Names'), ', '), or tidy each piece with a Select action that uses the split result in From and trim(item()) in Map.

Example 3: Split by new line

Text from a multiple-lines column, an email body or a long Forms answer is full of line breaks, and splitting it into lines is one of the most common requests I get. It’s also where most people get stuck, because typing '\n' in an expression doesn’t give you a line break. Power Automate treats it as two ordinary characters, a backslash and the letter n, so the split finds nothing.

The reliable way is to create the line break with decodeUriComponent(), where %0A is the code for a line feed:

split(outputs('Compose'), decodeUriComponent('%0A'))

There’s one more wrinkle. Text that comes from Windows or Outlook often has a carriage return before each line feed (%0D%0A), which leaves an invisible character at the end of every line. To handle both formats, remove the carriage returns first and then split:

split(replace(outputs('Compose'), decodeUriComponent('%0D'), ''), decodeUriComponent('%0A'))

Here’s a Compose action with text on several lines, and the array you get after splitting it:

Compose action with text on several lines in Power Automate
Result of splitting text by new line in Power Automate

Example 4: Get the first, last or Nth item

Often you don’t need the whole array, just one piece of it. Because split() returns an array, you can pick a piece directly in the same expression. This table uses the text San Francisco,Seattle,Boston:

You wantExpressionResult for ‘San Francisco,Seattle,Boston’
First itemfirst(split(variables('Cities'), ','))San Francisco
Last itemlast(split(variables('Cities'), ','))Boston
Second item (index starts at 0)split(variables('Cities'), ',')[1]Seattle
Number of itemslength(split(variables('Cities'), ','))3
All items except the firstskip(split(variables('Cities'), ','), 1)[“Seattle”,”Boston”]
Get the last element of a split string in Power Automate

Be careful with fixed positions. An index like [2] makes the flow fail if the text has fewer than three pieces, which happens more often than you’d expect with user input. Check the length first: if(greater(length(split(x, ',')), 2), split(x, ',')[2], '').

A handy use of last() is getting a file extension. last(split(triggerOutputs()?['body/{FilenameWithExtension}'], '.')) returns pdf for Report.final.pdf, because it takes the text after the last dot, however many dots the name contains.

Example 5: Split a string into an array and loop through it

Sometimes text contains several records, each with several fields, such as Employee Name:David:25 | Employee Name:Henry:32. The approach is to split twice: first into records, and then each record into its fields.

Add a Compose action with the string. Then add an Initialize variable action with Type set to Array, and use this expression as the Value, which splits the text into one item per employee: split(outputs('Compose'), '|').

Initialize an array variable with split() in Power Automate

Now add an Apply to each action and select the array variable. Inside the loop, add a Compose action with split(trim(items('Apply_to_each')), ':'). The trim() removes the spaces around each record before the second split.

Split each item inside an Apply to each loop in Power Automate

Each run of the loop now has a small array for one employee, such as ["Employee Name","David","25"], so you can use outputs('Compose_2')[1] for the name and [2] for the age.

Output of splitting each item in the loop in Power Automate

Remove empty items after a split

Because split() keeps empty pieces, text such as a,,b, gives you blank items, which then create empty rows or failed actions further down the flow. The cleanest fix is a Filter array action. Set From to split(variables('Text'), ','), and set the condition to item() is not equal to with the right side left empty. The Filter array output contains only the pieces that have text in them.

Split on several delimiters

There’s no way to give split() more than one delimiter at once. When your text mixes separators, for example commas, semicolons and pipes, replace them all with a single delimiter first and then split:

split(replace(replace(variables('Text'), ';', ','), '|', ','), ',')

Join the pieces back together

join() does the opposite of split(): it turns an array back into text, with a delimiter between the items. I use the two together most often for email recipients, where a comma-separated list needs to become a semicolon-separated one:

join(split(variables('Emails'), ','), ';')

split() vs Split On vs Split text

Three features in Power Automate have “split” in their name, and they’re easy to confuse in search results. Here’s how they differ:

FeatureWhereWhat it does
split() functionExpressions in cloud flowsSplits text into an array inside one flow run
Split on settingTrigger settingsStarts a separate flow run for each item of an array the trigger returns (for example rows from a trigger)
Split text actionPower Automate for desktopSplits text by Space, Tab, New line, a custom delimiter or a regular expression, and returns a list

These Power Automate string and array guides go well with split():

Frequently Asked Questions

How do I split a string into an array in Power Automate?

Use split(‘text’, ‘delimiter’) in an expression, for example split(variables(‘Names’), ‘,’). It returns an array with one item for each piece between the delimiters.

How do I split by new line in Power Automate?

Use decodeUriComponent(‘%0A’) as the delimiter: split(outputs(‘Compose’), decodeUriComponent(‘%0A’)). Typing ‘\n’ doesn’t work, because Power Automate treats it as two normal characters.

How do I get the first or last item after a split?

Wrap the split in first() or last(), for example last(split(variables(‘Cities’), ‘,’)). For another position, use an index such as split(variables(‘Cities’), ‘,’)[1], which returns the second item.

Does split() remove empty values?

No. split() keeps empty pieces, so ‘a,,b’ returns three items. Remove them with a Filter array action where item() is not equal to an empty value.

What is the difference between split() and Split On?

split() is a function that splits text into an array inside one run. Split On is a trigger setting that starts a separate run of the flow for each item in an array.

7 thoughts on “Power Automate split() Function: Split a String Into an Array (With Examples)”

    • I had one case that i had to get the file name and split it to get some values that were a pattern of the file name, so i used the split to get this values and add to others variables

      • Hi Tiago – I’m in a similar position whereby I need to split the file name into some values and then put the values under respective columns in SharePoint. May you please kindly point me into the right direction?

  1. Great tutorial! Need next step: once I have broken a string into separate lines (i.e.: “Alex”, “Emma”, “Ruby”, “Stwart”) how can I transfer each line into, for example, the fields in a “Create Item” action?

  2. I have a SharePoint list contains different columns but for me one colomn which have data like ZDFTR5F,ZXD4DF,ZXD5F,ZXDR56,ZXDS4R I want this data in different rows or colomns for each data in a excel sheet how can I create a powerautomation flow or give me some expression for compose field please help me guys

  3. I got compose variable output is this, I want to split these into three words (1: Test Match, 2: Dressing Room and 3.reconnected) I want to remove (‘s)
    [
    “Test Match’s Dressing Room “,
    ” reconnected.”
    ]

Comments are closed.