Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

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

Posted on April 28, 2021May 23, 2021 by Tom

“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.

8 thoughts on “How to add new line (‘\n’) to a string in Power Automate”

  1. Joseph Boland says:
    August 1, 2021 at 12:06 am

    Thanks! Used decodeUriComponent easily and successfully to format the Notes field in a Planner task with output from a Forms survey.

    Reply
  2. Alan says:
    September 9, 2021 at 4:15 pm

    Thank you SO MUCH! I have been trying to figure this out for a little while and have not found a solution that works until I found this blog post. Cheers!

    Reply
  3. Anitha says:
    November 10, 2021 at 7:58 pm

    Much useful. Thank you.

    Reply
  4. Marcio says:
    December 14, 2021 at 3:38 pm

    Great! thks!

    Reply
  5. Valentin Joubert says:
    January 2, 2023 at 11:45 am

    Great THX

    Reply
  6. Ana says:
    May 8, 2023 at 5:28 pm

    Hello!

    I have a string variable in a for each where I concatenate several strings and I want to finish with a new line for the following iteration to store the values in a new line because I need to show those values into an e-mail that I´m sending, but I´ve tried all the ways explained, and none worked for me 🙁 It’s still printing the values without line break, any ideas? I would be very gratefull if you could help me 🙂

    Thanks in advance,
    Regards

    Reply
    1. Tom says:
      May 28, 2023 at 2:57 pm

      Hello Ana,
      emails use HTML formatting so I’d try adding the
      tag at the end of the line instead of this solution.

      Reply
  7. Ram says:
    July 16, 2023 at 10:22 am

    Thanks a lot, saved me so much time.

    Reply

Leave a Reply Cancel reply

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

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

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.

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with 1000s of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes