Power Automate Replace() Function

As a Power Platform developer, you might be required to use the replace function in Power Automate. This is very common in most real-world use cases. So, I thought to explain the Power Automate replace expression.

In this tutorial, I will explain the Power Automate replace() function, focusing on its practical application in real-world examples. Let’s see how to use the Replace function in Power Automate.

Replace() function in Power Automate

The Replace() function in Power Automate is used to find a specific part of a text (string) and replace it with something else. This is very useful when you want to change, remove, or update certain words or characters in your data automatically.

power automate replace function

The Power Automate Replace() function syntax is as follows:

replace(text, oldText, newText)
  • text: This is the original text where you want to make changes.
  • oldText: This is the part of the text you want to find and replace.
  • newText: This is what you want to put instead of the oldText.

Example:

Let’s say you have the text:

"Hello World!"

And you want to change “World” to “Power Automate”.

You would use:

replace('Hello World!', 'World', 'Power Automate')

The result will be:

"Hello Power Automate!"

Check out How to Filter an Array by Date in Power Automate?

How to Use the Replace Function in Power Automate

Now, let us see how to use the replace() function in Power Automate with some real examples.

Example 1: Replace String in a Variable

Suppose you have a variable with a text string named ‘ Power Automate Cloud Flow’ and you want to replace the ‘Cloud ‘ with ‘Desktop‘ as a string. So that the end result will be ‘Power Automate Desktop Flow’.

To do this, follow the steps below:

  1. Create an Instant cloud flow in Power Automate.
  2. Next, add an “Initialize variable” action to store the text string. Set the properties.
    • Name: Provide a name for the variable.
    • Type: Select type as a string.
    • Value: Enter the value of a string.
Power Automate replace string
  1. After that, add another “Initialize variable” action to store the replacement string. Provide the parameters, such as Name, Type, and Value.
Power Automate replace string in variable
  1. Now, add a “Compose” action to replace the string with replacement text. Give the expression below.
replace(variables('Var1'),'Cloud',variables('Var2'))
Replace string variable in Power Automate
  1. Then, save and run the flow manually. After the flow execution, check the compose outputs section. You can see that the text string will be replaced with the text that we provided in the variable. Below if the screenshot for your reference.
Replace string in variable Power Automate

This is an example of using the replace function in Power Automate.

Read How to Filter an Array by Index in Power Automate?

Example 2: Power Automate Replace Character in String

Let me explain another example of replace() in Power Automate. This example will show you how to replace a character in a string using Power Automate.

Suppose I have a text value as [Power Apps | Power Automate | Power BI | Power Pages]. I want to replace the instances of the character “|” with another character, ie, “,“.

Check out the steps below:

  1. To the flow, take an “Initialize variable” to store the text string value in a variable. Provide Name, select type as String, and value as below.
Power Automate string replace character
  1. Then, add a “Compose” action to the flow. Copy and paste the expression provided in the code below.
replace(variables('Power Platform'),'|',',')
String replace character Power Automate
  1. After that, save and run the flow. Open the compose action, which will display the following output.
Power Automate replace text with character

This is how to replace a character in a string using Power Automate.

Check out How to Filter an Array by String Values in Power Automate?

Example 3: Power Automate Replace String With Blank

Suppose you have the following data source as a SharePoint list [Budget List], and you want to replace the text “TS-” while retaining only the numeric part in the Budget ID column.

Power Automate replace string with blank

This can be done by replacing the “TS-” string with a blank value.

Here, I will trigger Instant cloud flow, which will run based on a button click. Follow the steps below:

  1. To retrieve the items from a SharePoint list, add a “Get items” action. Provide Site Address and List Name.
Replace string with blank Power Automate
  1. Next, add a “Compose” action to give the expression that will replace the string with blank values.
replace(items('For_each')?['BudgetID'],'TS-','')

This will automatically add a For Each loop by taking the body/values from the dynamic content of the Get Items action.

Power Automate replace text with blank
  1. Inside the For Each loop, add the “Update item” action to update each item with the replaced text. Set the parameters, such as Site Address and List Name.
    • Id: Choose to add ID from the Get items action of the previous step.
    • Budget ID: Select the outputs of the compose action from the dynamic content.
replace function Power Automate

Now, the flow is ready. Manually run the flow.

Output:

Power Automate replace text string with blank

Check out Update SharePoint List Items from Excel using Power Automate

Power Automate Replace() Function – Video Tutorial

Here is a useful video that you can follow to learn how to use the replace() function in Power Automate.

I hope you now understand how to use the replace function in Power Automate. You can mention your suggestions or questions in the comment section.

You may also like the following Power Automate functions tutorials:

  • Hi, great article. Can you give us an example on how to uppercase or lowercase very first character from each word in a string? For example: this is a sentence => This Is A Sentence

    Kind regards
    Adrian

  • >

    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…