Mastering Power Automate: The Power of the split() Function

Unlock Workflow Efficiency with Power Automate's split() Function

When constructing workflows in Microsoft Power Automate, you'll frequently encounter scenarios where multiple values are delivered as a single text string. To effectively process each of these values individually, the crucial step is to convert that string into an array. Fortunately, Power Automate provides a straightforward and highly efficient solution: the split() function.

This article will guide you through the practical application of the split() function, illustrating its utility with common use cases and clear examples.

Why Leverage the split() Function?

The split() function is an indispensable tool for several key reasons:

Understanding the split() Function

The syntax for the split() function is elegantly simple:

split('','')

Parameters Explained:

Example 1: Splitting a Comma-Separated String

Imagine you have the following string:

Apple,Banana,Orange

To convert this into an array, you would use the following expression:

split('Apple,Banana,Orange',',')

The resulting output will be an array:

[
  "Apple",
  "Banana",
  "Orange"
]

Example 2: Splitting a Semicolon-Separated String

For strings using a different separator, like semicolons:

Input: John;Peter;David

Expression: split('John;Peter;David',';')

Output: ["John", "Peter", "David"]

Example 3: Splitting Dynamic Content

When dealing with dynamic content, such as values received from a form submission, a SharePoint column, or a Dataverse field, the process is similar. For instance, if you receive a string of email addresses:

Email1@company.com,Email2@company.com,Email3@company.com

You would use an expression like this, referencing the dynamic content:

split(triggerBody()?['Emails'],',')

This expression dynamically creates an array from the 'Emails' field, which can then be readily processed within an Apply to Each action.

Utilizing split() with Apply to Each

Once you've successfully converted your string into an array using split(), the next logical step is often to process each item in that array individually. This is where the Apply to Each control becomes invaluable.

  1. Add an Apply to Each action to your flow.
  2. In the Select an output from previous steps field, choose the output of your split() expression.
  3. Within the Apply to Each loop, you can now add actions to process each value independently.

For example, if you split the string '1001,1002,1003' using a comma delimiter:

split('1001,1002,1003',',')

The Apply to Each loop will iterate through the resulting array, processing each item (1001, 1002, 1003) one at a time.

Common Use Cases for split()

Combining split() with Other Functions

The power of split() is amplified when combined with other useful Power Automate expression functions:

Best Practices for Using split()

To ensure robust and reliable workflows, keep these best practices in mind:

Real-World Scenario: Email Notifications from SharePoint

Consider a common scenario where a SharePoint list has a single text field designated to store multiple email addresses, separated by commas:

john@company.com,mary@company.com,david@company.com

Using the split() function, you can convert this comma-separated string into an array. Subsequently, you can employ an Apply to Each loop to iterate through this array and send individual notification emails to each recipient. This approach significantly enhances the flexibility of your workflows and makes them far easier to maintain and troubleshoot.

Conclusion

The split() function stands out as one of the most valuable expression functions available in Microsoft Power Automate. It empowers you to transform raw text strings into structured arrays, simplifying the process of handling multiple values, iterating through records, and ultimately building more dynamic and adaptable workflows.

By strategically combining split() with other Power Automate functions, you can achieve efficient data transformation and gain greater control over your automation solutions.