Power Automate Substring Function: Explanation, Examples, Best Practices

tim-van-der-kuip-CPs2X8JYmS8-unsplash
Power Automate Power Platform

Power Automate Substring Function: Explanation, Examples, Best Practices

Microsoft’s Power Automate is a robust platform that enables businesses to automate routine tasks, streamlining operations and freeing up essential resources. Among the many features Power Automate offers, one that stands out for its utility is the substring function. This function is crucial for manipulating and extracting valuable insights from text data.

This article will delve into the details of the power automate substring function, including its explanation, examples, best practices, and impacts.

The Power Automate Substring Function: An Overview

The power automate substring function is a tool designed for string manipulation. It allows users to extract a section of a string based on the start index and the length of the desired substring.

The substring function in Power Automate can significantly influence the efficiency and accuracy of string operations. It aids in extracting necessary data from larger text fields, which can then be used for various purposes such as data analysis, reporting, or decision-making. Furthermore, the function enhances the flexibility of the platform, allowing it to handle a wide range of tasks involving string manipulation.

Let’s delve into the process of creating a simple Power Automate flow that will demonstrate the use of the substring and other string functions. The steps outlined will guide you through initializing a variable, utilizing the compose action, testing the flow, and more.

creating a simple Power Automate flow with substring

Step 1: Create a New Instant Cloud Flow

Create a New Instant Cloud Flow
  1. Navigate to Power Automate and select “Create” from the left-hand menu.
  2. In the ensuing options, select “Instant cloud flow“.
  3. Enter a name for the flow in the “Build an instant cloud flow” box.
  4. Select “Manually trigger a flow” under the “Choose how to trigger this flow” section, and click “Create“.

Related reading: Power Automate Trigger Conditions: Example-Based Guide

Step 2: Initialize a Variable

 Initialize a Variable
  1. In the new screen, click “New Step“.
click "New Step"
  1. Search for “Initialize variable” in the actions search box and select the action.
  2. In the “Name” field, type “string_1“.
  3. Choose “String” as the “Type“.
  4. In the “Value” field, enter “Citizen Development Academy power automate“.

Step 3: Use Compose Action and Substring Formula

  1. Click on “New Step“.
  2. Search for the “Compose” action and select it.
 Use Compose Action and Substring Formula
  1. In the “Inputs” field, enter the following formula: substring(variables(‘string_1’),28,14). This formula will extract the first word ‘Citizen’ from the string.

Read also: Understanding Power Automate Compose

Step 4: Save and Test the Flow

  1. Click on “Save” at the top-right corner of the screen to save the flow.
  2. To test the flow, click on the “Test” button located at the top-right corner next to the “Save” button.
Save and Test the Flow
  1. In the ensuing pop-up, select “Manually” and click “Test“.
  2. Click “Run flow” and then “Done” in the trigger window.

Step 5: Inspect the Output

Once the flow runs successfully, inspect the output in the “Compose” action. It should display the result ‘Citizen’, indicating that the substring function has successfully extracted the first word from the initialized string.

Inspect the Output

Power Automate Substring After Character: The Tradeoffs

Extracting a substring after a specific character in Power Automate is a common requirement. This involves finding the position of the specific character in the string, and then using the substring function to extract the remaining text. While this approach is straightforward and effective, it does come with certain trade-offs.

Firstly, the complexity of the operation increases when dealing with special characters or multiple occurrences of the character. This necessitates the implementation of additional logic to handle such scenarios. Secondly, this approach can lead to errors if not handled properly, especially when the character is not found in the string.

Read also: How to Populate a Word Document Template with Power Automate

Other String Operations in Power Automate

FunctionDescriptionInput Parameters
and Data Types
Output Data
Type
CONCAT([string1],…,[stringN])Concatenates given strings[string1] – STRING;
[stringN] – STRING
STRING
CONTAINS([string],[value])Returns TRUE if the string contains the given value, else FALSE[string] – STRING; [value] – STRINGBOOL
ENDSWITH([string],[value]) / STARTSWITHReturns TRUE if string ends with the given value, else FALSE[string] – STRING; [value] – STRINGBOOL
LEFT([string],[count]) / RIGHTExtracts a given number of characters from the left side of a supplied text string[string] – STRING; [count] – INTSTRING
LEN([string])Returns the length of the string[string] – STRINGINT
LOWER([string])Returns a lower-case version of a given text string[string] – STRINGSTRING
LTRIM([string]) / RTRIMRemoves whitespace from the beginning of the string[string] – STRINGSTRING
TOSTRING([int],[format]*)Converts an integer to a string according to the formatting string[int] – INT; [format]* – STRINGSTRING

Recommended reading: How to Send Emails with Power Automate

The Power Automate Substring Function: Challenges

One of the main challenges associated with the power automate substring function is handling errors. If the starting index or length specified exceeds the actual length of the string, the function will return an error. Hence, it is crucial to ensure that these parameters are within the bounds of the string length.

Power Automate Substring Function: Challenges
Challenges of using Power Automate Substring Function

Another challenge is dealing with complex string manipulation tasks. In such cases, the power automate substring function may need to be used in conjunction with other functions or expressions, increasing the complexity of the operation.

Power Automate Substring Expression: Exploring the Complexities

The power automate substring function is not just limited to simple extraction of substrings. It can also form part of a complex expression that involves other functions. For instance, one might need to first split a string into an array and then extract a substring from each element of the array. This highlights the versatility of the substring function but also adds another layer of complexity to its usage.

You may also like: How to Use Power Automate Filter Query

Best Practices for Using Power Automate Substring Function

Implement Error Handling

When using the Power Automate substring function, always include error handling to address situations where the starting index or length exceeds the string length. This proactive measure helps prevent complications and setbacks.

Break Down Complex Tasks

For complex string manipulation tasks involving the substring function and other expressions, break the operation into smaller, more manageable steps. This approach makes the process less daunting and easier to manage.

Be Cautious with Special Characters

Exercise caution when working with special characters or multiple occurrences of a character. The risk of errors increases, and additional logic may be necessary to handle these scenarios.

Validate Parameters

Ensure that the starting index and length parameters for the substring function are within the bounds of the string length. Neglecting this aspect could lead to errors and potential issues.

Test Your Flows Thoroughly

Don’t overlook the importance of testing. Rigorous testing of your flows ensures they function as expected, helping you avoid unforeseen problems later on.
By understanding the Power Automate substring function and adhering to these best practices, you can harness its full potential and enhance the efficiency of your string operations. Keep refining your skills and leveraging Power Automate to streamline your business processes.

Conclusion

In wrapping up, the substring function is a game-changer for creating flows in Power Automate more dynamic. By following simple best practices like robust error handling, careful task breakdown, and thorough testing, you can navigate these challenges effectively. Harnessing this function can significantly streamline your business operations, enabling you to extract the most value from your unstructured data.

Do you want to learn more about Power Automate and its possibilities? Take a look at our course Power Automate Training: Learn How to Automate Your Business Processes.

FAQs:

How do you get a substring in Power Automate?

To extract a specific portion from a string in Power Automate, the substring function is your best tool. It requires three inputs: the original string, the start position, and the substring length. Keep in mind that counting begins from 0.

How do I split a string into an array in Power Automate?

To split a string into an array in Power Automate, you can use the split function. This function divides a string based on a specified delimiter, creating an array of substrings.

How do you strip characters from a string in Power Automate?

If you're looking to remove certain characters from a string in Power Automate, the replace function is the tool you need. You can use it to swap out a specific character or a group of characters for another, or simply erase them by swapping them out for an empty string.

How to extract a string from a substring?

Finally, to draw out a string from a substring, you can once again rely on the trusty substring function in Power Automate. You'll need to provide the initial string, the starting position, and the length of the substring you're after.

Comment (1)

  1. Muhammad

    Thank you for these detailed instructions!

Leave your thought here

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