#PowerPlatformTip 141: Text to Array
TL;DR: Turn a multiline text block into a loopable array in Power Automate with
split(text, separator).
💡 Challenge
How do you process a copied multiline text block, each line a record (IDs, email addresses, URLs), in a Power Automate flow without splitting it by hand? Manual steps don’t scale and are error-prone.
✅ Solution
Use the split() expression to turn the multiline string into an array. With a simple separator (a line break, comma, or any character) you get an array you can loop through with “Apply to each”.
🔧 How It’s Done
1. Capture the text
🔸 Add a Compose action and paste your multiline text into it. Name it DataInput.
2. Define the separator
🔸 Add a second Compose with the expression decodeUriComponent('%0A') (line feed). Name it Separator.
3. Loop the array
🔸 Add an Apply to each control and set its input to:
1
split(outputs('DataInput'), outputs('Separator'))
4. Process each line
🔸 Inside the loop, use trim(item()) to remove surrounding whitespace before validating or processing each line.
Real flow run: a 3-line block of email addresses goes in, and comes out as a clean 3-element array, alice@example.com, bob@example.com, carol@example.com, ready for “Apply to each”.
Real flow run: Code View confirms the actual expression, split(outputs('Multiline_Text_Block'), decodeUriComponent('%0A')), splitting on the newline character.
🧩 Line Breaks, Empty Lines and Chunks
Three things bite once the text comes from Windows, Outlook or a form instead of a tidy Compose. All results below are from one flow run with the input a, b, an empty line and c, separated by Windows line breaks (\r\n).
1. \n is not enough when the source uses \r\n.
🔸 split(text, decodeUriComponent('%0A')) returns ["a\r", "b\r", "\r", "c"]: every item except the last still carries the carriage return, length(first(...)) is 2 and equals(first(...), 'a') is false.
🔸 Split on both characters, split(text, decodeUriComponent('%0D%0A')), and you get ["a", "b", "", "c"].
🔸 Source unknown? Strip the \r first, then split on \n, this handles both Windows and Unix line breaks:
1
split(replace(outputs('DataInput'), decodeUriComponent('%0D'), ''), decodeUriComponent('%0A'))
2. Empty items are real items.
🔸 split('', ',') returns [""], one empty element, not an empty array. split('a,b,', ',') returns ["a", "b", ""].
🔸 Remove them before the loop with a Filter array action on the split result, condition in advanced mode:
1
@not(empty(trim(item())))
🔸 ["a", "b", "", "c"] comes out as ["a", "b", "c"].
3. Split an array into blocks with chunk().
🔸 chunk(createArray(1,2,3,4,5,6,7), 3) returns [[1,2,3],[4,5,6],[7]], the last block holds the remainder.
🔸 It also works on text: chunk('abcdefg', 3) returns ["abc", "def", "g"].
🔸 Typical use: feed an API that accepts 20 IDs per call, loop over chunk(variables('ids'), 20) and join(item(), ',') inside.
🎉 Result
Your flow now accepts any multiline text block and processes each line as a separate item. No more copy-paste, no manual cleanup, just reliable automation that scales.
🌟 Key Advantages
🔸 Saves time by automating repetitive data preparation
🔸 Flexible: works with lists from Excel, emails, Power Apps, or paste operations
🔸 Reduces human errors from manual handling
🔸 Scales to hundreds or thousands of lines without extra effort
🎥 Video Tutorial
🛠️ FAQ
1. What if my data is comma-separated instead of line breaks? Replace the Separator Compose content with a comma. The same split() expression produces the array.
2. Can the text originate from a Power App? Yes. Pass a multiline text input from Power Apps into the flow; the split logic stays identical.
3. How do I handle empty lines from accidental extra newlines? Add a condition inside the loop to check that trim(Current item) is not empty before processing, or filter them out once before the loop with a Filter array action and @not(empty(trim(item()))).
4. Why do my split items end with \r? The text uses Windows line breaks (\r\n) and you split on \n only. Split on decodeUriComponent('%0D%0A'), or remove decodeUriComponent('%0D') with replace() before splitting.
5. How do I split an array into smaller arrays? chunk(array, size) returns an array of arrays: chunk(createArray(1,2,3,4,5,6,7), 3) gives [[1,2,3],[4,5,6],[7]]. It works on strings too, chunk('abcdefg', 3) gives ["abc","def","g"].
🔗 Related Tips
- #PowerPlatformTip 120: PowerAutomate Text Processing 2.0, advanced text manipulation actions.
- #PowerPlatformTip 24: Merge Arrays or Tables, combine arrays after splitting.
This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).