Power Automate substring() Function [How to Use]

While working with a requirement, I had to extract a portion of a string (a substring) based on specified parameters. I utilized the Power Automate substring() Function to make this happen. Additionally, it occurred to me to share my idea for this function through an article.

This tutorial explains what is a substring() function in Power Automate, its syntax, and how to use this function with various examples like:

  • How to use the Power Automate substring() function manually
  • Working with the substring() function in Power Automate using a SharePoint list

Power Automate substring() Function

The Power Automate substring() function is one of the string functions designed for string manipulation during the flow. This function can be useful for extracting the necessary data from large text fields for various purposes like decision-making, data analysis, etc.

The Power Automate substring() function extracts part of a given text, a character, or a specific section of a provided string based on the starting position and length of a substring.

The datatype returned from the substring() function in Power Automate will be a string.

Power Automate Substring() Function Syntax

The Power Automate substring() function syntax is below:

substring(string, startIndex, length)
  1. string: The string from which a substring will be extracted.
  2. startIndex: The zero-based index position in the string where the extraction of characters starts.
    • Example: Power Automate -> ‘P’ start index is ‘0’. Similarly, For ‘o’ start index is ‘1’, and For ‘A’ start index is ‘6’. Note: First character on the position of ‘0’.
  3. length (Optional): The number of characters to extract. If this parameter is not provided, the function extracts characters from the start index to the end of the string.
    • Example: Power Automate -> For ‘P’ start index is ‘0’; if the length is taken as ‘5’ – It returns as ‘ Power.’ If the length is not included in the expression, it will return as ‘Power Automate.’

Example:

substring(‘Microsoft Power Apps’,10,5) // Output – Power [Where ’10’ is the start index and ‘5’ is the length of the substring.]

How to Use Power Automate substring() Function Manually

Let me explain how we can manually use the substring() function in Power Automate. Refer to the instructions below:

1. Open the Power Automate Home page. Click on “+ Create” -> Select “Instant cloud flow” -> Set Flow name -> Choose “Manually trigger a flow” -> click on Create.

  • In the trigger, click on +Add an input -> Select Text.
Power Automate substring() function

2. To store the text values during the flow, add the Initialize variable flow action and set the details below:

  • Name: Set a name for an initialized variable
  • Type: Select datatype as ‘String’
  • Value: Here, I have given a text from the dynamic content.
Power Automate functions substring() function

3. After the initialized variable, add the “Compose” data operation to add the substring function along with the variable.

  • Inputs: Add the below-given expression it.
substring(variables('Text'),0,5)
Substring function in Power Automate

4. Now, it’s time to save and test the flow. Click on Save and Test. Test it Manually. I provided the text input in the Run Flow window as ‘Power Automate‘.

Note:

The length of a substring cant be longer than length of a source string. If it is longer than that, then the flow will result into an error.

Example: substring('Monday',0,7) => The length of a substring cant be longer than ‘6’ because the length of a source string is ‘6’ .

5. The compose flow action will display the part of a text string according to the start index and length of a substring.

Using substring() function in Power Automate flow

This is how to use the Power Automate substring() function manually.

Power Automate substring() Function Using a SharePoint List

In this scenario, we will see how to use the substring() function in Power Automate based on a SharePoint list.

  • I have a SharePoint list named Course Enrollment with a text column called Full Name.
How to use Power Automate substring() expression

Now, we will extract a certain part of a text string or character from the ‘Full Name’ column in a SharePoint list.

Follow the below step-wise process to implement it:

1. On Power Automate’s Home page, click + Create and select “Automated cloud flow”. Then, set the flow name, choose the trigger “When an item is created,” and click on Create.

  • In the trigger, set the Site Address and List Name.
Power Automate substring () Function example

2. Next, add an ” Initialize variable” flow action to store the values of text during the flow and provide details like Name, Type, and Value.

  • Value: Take value from the dynamic content.
Power Automate expressions substring() function

3. Then, add a “Compose” data operation and give the input as provided in the code below.

substring(variables('Name'),0,6)
How to use Power Automate substring() function

4. At this point, click on Save and then Test the flow Manually. Now, add an item to the SharePoint list.

Microsoft Power Automate substring() function

5. When the flow runs successfully, the outputs of the compose flow action will display a section of a given string according to the start index and length of a substring.

Power Automate substring() Function Using a SharePoint List

This is how to work with the Power Automate substring() function.

Conclusion

I hope this Power Automate tutorial helps you understand about Power Automate substring() function and its syntax.

Also, I have covered a few examples of substring() function in Power Automate like:

  • Example of substring() expression in a Power Automate Instant cloud flow
  • Power Automate substring() function using a SharePoint list

You may also like: