Split text into parts in Power Automate
Short answer: the split() function cuts one piece of text into an array of smaller pieces. You give it the text and one delimiter, which is the character to cut at. To keep only the first piece, wrap it in first(). To keep only the last piece, wrap it in last(). To split by new line, use a new line character as the delimiter.
This guide shows three jobs: get the first part, get the last part, and split a block of text into one piece per line. It also lists the mistakes that waste time.
What split() does
Microsoft's reference guide for expression functions (an Azure Logic Apps page that also covers Power Automate) describes split() like this: "Return an array that contains substrings, separated by commas, based on the specified delimiter character in the original string."
The syntax on that page is split('<text>', '<delimiter>'). Both parts are required. The page gives two examples. In the first, "This example creates an array with substrings from the specified string based on the specified character as the delimiter: split('a_b_c', '_')" and the result is ["a","b","c"]. In the second, there is no delimiter in the text, so the result is an array with a single element: split('a_b_c', ' ') returns ["a_b_c"].
Think of it as scissors. The text is the paper. The delimiter tells the scissors where to cut. The delimiter itself is removed. What you get back is a list of pieces, not one piece.
Before you start
- Open https://make.powerautomate.com and open the flow you want to change, or start a new one.
- Find the field that should hold the result. This can be an email body, a SharePoint column, or a step that only stores a value. Microsoft's page on data operations describes one such step: "Use the Compose action to create a single output, such as a JSON object, from multiple inputs." That page is an Azure Logic Apps page. The Compose step in Power Automate is similar, and exact names may differ in your screens.
- Know your delimiter. Look at a real example of your text and find the one character that sits between the parts. It might be a comma, a dash, a pipe, a dot or a line break.
Example 1. Get the first part
Say a code looks like 4411-West-Rush. The first part is the order number. One way to start:
first(split('4411-West-Rush', '-'))
split() returns ["4411","West","Rush"]. Microsoft's page says first() will "Return the first item from a string or array." Its example, first(createArray(0, 1, 2)), returns 0. So here the result is 4411.
In a real flow you do not type the text. You replace '4411-West-Rush' with the dynamic content for your column or field. In the expression box this looks like a token in place of the quoted text. If your column is named Code, the token is the Code column from your trigger or from Get item.
Example 2. Get the last part
Say a file name looks like Report.final.pdf and you want the ending. Use last():
last(split('Report.final.pdf', '.'))
Microsoft's page says last() will "Return the last item from a collection." Its example, last(createArray(0, 1, 2, 3)), returns 3. For the file name above, split() returns ["Report","final","pdf"] and last() returns pdf.
This is better than counting characters from the end. A file name with two dots still works, because last() always takes the last piece.
Example 3. Get a part in the middle
Sometimes you want the second piece of a three-piece code. Microsoft documents two functions that help. The page says skip() will "Remove items from the front of a collection, and return all the other items." It says take() will "Return items from the front of a collection."
One way to start: skip one piece, then take one piece.
first(skip(split('4411-West-Rush', '-'), 1))
split() returns ["4411","West","Rush"]. skip(..., 1) drops 4411 and leaves ["West","Rush"]. first() then returns West.
You can also use take() to keep the first two pieces, then last() on that. Pick whichever you can read at a glance. Our advice, not a Microsoft rule: choose the version that the next person on your team can read without help.
Example 4. Split by new line
A multi-line text box gives you one block of text with line breaks in it. To get one piece per line, the delimiter must be the line break character itself. Typing a line break into the formula box is awkward. One way to start is to build the character from its code. Microsoft documents decodeUriComponent(): "Return a string that replaces escape characters with decoded versions." Its example turns 'https%3A%2F%2Fcontoso.com' into "https://contoso.com".
The code for a line feed is %0A, so the delimiter can be written as decodeUriComponent('%0A'):
split(<your multi-line text>, decodeUriComponent('%0A'))
Our advice, not a Microsoft rule: this works for the plain line feed. Text that was typed on some systems or pasted from other tools can end each line with an extra invisible character. If your pieces look right but do not match when you compare them, wrap each piece in trim(). Microsoft's page says trim() will "Remove leading and trailing whitespace from a string, and return the updated string." Run the flow once with a real multi-line example and open the run history to check each piece before you rely on it.
Use every part, one at a time
split() returns an array, so you can process each piece. Add an Apply to each step and give it the output of split(). Inside the loop, the current piece is available with item(). Microsoft's page says item() will, "If this function appears inside a repeating action over an array, return the current item in the array during the action's current iteration."
A few notes:
- If you only need one piece, skip the loop and use first() or last().
- If you need the pieces back as one text again, Microsoft documents join(): "Return a string that has all the items from an array and has each character separated by a delimiter." Its example, join(createArray('a', 'b', 'c'), '.'), returns "a.b.c".
- If you use the pieces to create SharePoint items, keep the loop small. Our advice, not a Microsoft rule: test with three lines first, then with the real amount.
What to avoid
- Do not expect one value. split() returns an array. If you put the whole result in a text field, you see the brackets and quotes. Wrap it in first() or last(), or loop over it.
- Do not guess the delimiter. A space, a comma followed by a space and a bare comma are three different delimiters. Look at real data. Our advice, not a Microsoft rule: if the text may have a space after each comma, trim() each piece.
- Do not forget the quotes. The delimiter is text, so it goes in single quotes: '-' not -.
- Do not assume the text has the delimiter. Microsoft's second example shows what happens when it is missing: you get an array with one element, the whole text. If you take last() of that, you get the whole text back, not an empty value.
- Do not split text that can be empty without a test. Run the flow once with a blank value and see what each step returns before you rely on it.
- Do not build a long chain of nested functions in one box. Our advice, not a Microsoft rule: use one step for split(), a second for first() or last(), and name each step. When something breaks, you can open the run history and see which step failed.
- Do not paste a function into a field that expects a fixed choice. Text from split() will not match a Choice column unless the words are identical. See "Fix "Invalid type. Expected String but got Null" in Power Automate" if a step fails because a value arrives empty.
Check it worked
- Save the flow and run a test with a real example.
- Open the run and click the step that holds your expression.
- Read the output. For first(split('4411-West-Rush', '-')) it should read 4411.
- Try a second example that is a bit odd: a code with an extra dash, or one with no dash. Confirm the result is what you want.
- Only then turn the flow on for everyone.
When to get help
You can build all of this yourself in Microsoft 365. If you would rather have it built and tested for your team, I do that. A tracker like this is a fixed price: $5,000 for one, built in 2 weeks. See "What a SharePoint tracker costs to build". Bring one example of the problem to a free call.
I am Al Davies. I run 250 High Street LLC and build SharePoint trackers and Power Automate flows for operations teams. I work remotely. The first call is free, and I will not try to sell you anything.
See trackers I built: Tools I built
FAQ
How do I split a string in Power Automate?
Use split('<text>', '<delimiter>'). Microsoft's reference says it returns "an array that contains substrings". Put the text first and the character to cut at second, in single quotes. Then use first(), last() or a loop to use the pieces.
How do I get only the first or last part?
Wrap split() in first() or last(). For example, first(split('4411-West-Rush', '-')) returns 4411 and last(split('Report.final.pdf', '.')) returns pdf.
How do I split by new line?
Use the line feed code as the delimiter: split(<your text>, decodeUriComponent('%0A')). Microsoft documents decodeUriComponent(); the %0A code is our advice, not a Microsoft rule. Test with a real multi-line example and use trim() if pieces carry extra invisible characters.
Can I use more than one character as the delimiter?
Microsoft's page describes the delimiter as "The character in the original string to use as the delimiter". Our advice, not a Microsoft rule: use one character, and if your data uses a longer separator, run a test first or use replace() to swap it for one character before you split.
Why does my result show brackets and quotes?
Because split() returns an array, not text. Use first(), last() or join() to turn the array into a single value.
Sources
- Microsoft Learn, Reference guide to workflow expression functions in Azure Logic Apps and Power Automate
- Microsoft Learn, Use expressions in conditions in Power Automate
- Microsoft Learn, Perform data operations in workflows (Azure Logic Apps)