How to Replace Commas With New Lines in Power Automate

While working on a project named Employee Satisfaction Survey, I encountered a requirement to replace commas with new lines in Power Automate. Initially, I thought this could be easily achieved using the replace() function, which follows this format:

replace(text: string, oldText: string, newText: string)

However, when I tried using \n, char(10), or even HTML <br> tags as the newText Value, they didn’t work as expected. After some research and testing, I found two easy ways to replace commas with new lines in Power Automate:

  • Using a new line in a variable.
  • Using a new line from an expression.

In this tutorial, I will walk you through both methods to effectively replace commas with new lines in Power Automate.

Replace Commas with New Lines in Power Automate Using Variable

Let’s see how to replace commas with new lines in Power Automate using a variable.

1. Create an Instant Cloud Flow by selecting the ‘Manually trigger a flow’ trigger action.

replace new line with comma In Power Automate

2. Now add Initialize variable action and provide the below parameters:

  • Name: Provide like varPowerPlatform.
  • Type: Select a string in the drop-down.
  • Value: Provide the below value, or you can provide it as required.
Power App,Power Auomate,Power BI,Power Pages,Power Virtual Agent
power automate split by new line

3. Then add another Initialize variable action and provide the below parameters:

  • Name: Provide like varLineBrack.
  • Type: Select a string in the drop-down.
  • Value: Leave as blank.
power automate new line in string

4. Add the Compose action and provide the below expression:

replace(variables('varPowerPlatform'),',',variables('varLineBrack'))
Replace Commas with New Lines in Power Automate Using Variable

Now save the flow and run the flow manually. After the flow runs successfully, select the compose action output. You can see a new line has already replaced the commas.

Replace Commas with New Lines in Power Automate in Variable

Replace Commas with New Lines in Power Automate Using Expression

You have a SharePoint list named Employee Feedback, where employees submit their feedback. The “Suggestions” column is a multi-choice field, and when retrieved in Power Automate, the values appear as a comma-separated string like:

Better Work-Life Balance,More Training,Flexible Work Hours

However, we want to store this data in another “Formatted Suggestions” column where each value appears on a new line for better readability.

To do this, follow the below steps:

1. Create an Automated Cloud Flow using the SharePoint connector’s When an item is created trigger. Select the SharePoint site where your Employee Feedback list is present, and choose the Employee Feedback list.

Replace Commas with New Lines in Power Automate Expression

2. Add a compose action and provide the below expression to replace the comma with a new line:

replace(triggerBody()?['Suggestions'],',',decodeUriComponent('%0A'))
  • triggerBody()?[‘Suggestions’]: This retrieves the value of the Suggestions field from the trigger.
  • replace(… , ‘,’, decodeUriComponent(‘%0A’)):
    • replace(text, ‘,’, new_value): Replaces all occurrences of ‘,’ with the new value.
    • decodeUriComponent(‘%0A’): Decodes %0A, which represents a new line (line break).
How to replace new line (&#039;n&#039;) in a Power Automate expression

Save the flow and run it manually. Then, go to the SharePoint list and add a new item.

Power Automate Easily Replace New Line in Flow Expression

After the flow runs successfully, check the compose action output section. You can see that the compass has now been replaced with a new line.

Replace Commas with New Lines in Power Automate Using Expression

Conclusion

In this tutorial, I covered two easy ways to replace commas with new lines in Power Automate. First, I explained how to achieve this using a variable by initializing an empty string variable and using it in the replace() function. Then, I showed how to replace commas with new lines using an expression by leveraging decodeUriComponent(‘%0A’).

You may like the following tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…