How to add new line (‘\n’) to a string in Power Automate

“I am building a Power Automate flow and need to append values into a string variable, how can I add a new line/line feed into the variable”


When you build a string in Power Automate, sometimes you don’t want one long string. Having everything on a single line might be easier to work with, but terrible to read. And if user readability is important for your solution, you might need to add a few line breaks. In a reverse to replacing new lines, let’s take a look on adding new lines to a string.

Add new line in an action

The simplest solution is to add the new line directly in the editor. Enter all the dynamic content you want to turn into a string, including the format, into an action. You can use spaces, new lines, special characters… design the whole string visually.

Power Automate add a new line to a string

Note: if you’re appending the string to a variable, don’t forget to add one extra new line at the end. The next string will start on the new line.

Add new line to concat(…) expression

Another approach to building a string is using an expression. Instead of a separate action to build it visually, you can use the concat(…) expression. It’ll take all the values separated by a comma and turn them into a string.

concat('string1','string2','string3')
->
string1string2string3

To add a new line into the string you must add the ‘new line’ character as one of the values. There’re three options how to do that.

Add ‘Enter’ into the expression

The first one is to add ‘Enter’ into the expression. Add opening single quote, press Enter on your keyboard, and then add the closing single quote. It’ll split the expression on multiple lines, but Power Automate will translate it as a new line character.

concat('string1','
','string2','
','string3')
->
string1
string2
string3
Power Automate add new line

Create ‘new line’ variable and use it in the expression

The second approach is to create a new variable with the ‘new line’ character. Initialize a new string variable, and in the ‘Value’ field press Enter. Such variable can then be used in the concat(…) expression as a new line.

concat('string1',variables('var_newLine'),'string2',variables('var_newLine'),'string3')
->
string1
string2
string3
Power Automate add new line variable

Use decodeUriComponent(‘%0A’) expression

The third, and my preferred approach is to use the decodeUriComponent(‘%0A’) expression. As already explained in the article on replacing new lines in a string, the expression will give you the ‘new line’ character. With this expression you don’t need a special variable nor depend on the expression “layout”.

concat('string1',decodeUriComponent('%0A'),'string2',decodeUriComponent('%0A'),'string3')
->
string1
string2
string3
Power Automate add new line expression

Summary

As you can see, it can be simple or not so simple to add a new line to a string in Power Automate. If you can format the string directly in an action, do it. It’s easy to design, easy to work with, and it can be done by everyone without the expressions knowledge. It’s an approach I use when building simple approval history on document libraries in plain text instead of html table.

The expression approach can get a bit confusing if you’re building strings from multiple pieces. As you can’t format the string visually, it’s quite easy to get lost in all the pieces of the expression. I’d recommend using it only if you can’t format the string in an action, e.g. when exporting data to .csv or creating an html table.

And as already mentioned in a note, if you’re appending to a string, don’t forget to add a new line at the end of each string.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

2 Comments

Add a Comment

Your email address will not be published. Required fields are marked *