Power Automate length() Function [With Examples]

Do you know how to calculate the length of a string or an array in Power Automate? If you are not aware, then check out this complete tutorial.

This blog post will guide you about the Power Automate length() Function and syntax. Furthermore, by digging deep, I will explain how to use the Power Automate length() function with examples based on Automated and Instant cloud flow.

Power Automate length() function calculates the length of characters in a string, which means the number of characters included in a string or the number of items in an array. 

Power Automate length() Function

Microsoft Power Automate length() function determines the length of a string or the number of elements present in an array. The Power Automate length() function also considers spaces as characters and counts them as an output.

When the input value is an array, the function returns the number of elements [items] contained within the array.

Alternatively, when the input value is a string, it returns an integer value representing the total number of characters, including spaces, within the string.

Example:

I have taken text input with Country values as with array format [“Washington,” “Minnesota,” “Texas,” “New York,” “California“]. I wanted to check the number of elements in a country’s array. Then, the result will be “5“.

Here, it determines the number of items in an array. Refer to the below image.

Power Automate length() Function

This is a brief introduction to the Power Automate length() function.

Power Automate length() Function Syntax

The syntax for the Power Automate length() function looks like below:

length('collection:string')
length(collection: array)

Input Parameter:

  • Collection: A mandatory parameter can be either an array or a string. It represents the data for which you want to determine the length.

Return Value:

This function returns an integer representing the length of the input collection.

  • If the input is a string, it returns the number of characters in the string.
  • If the input is an array, it returns the number of elements (items) in the array.

Here is the syntax format for the Power Automate length() function.

How to Use Power Automate length() Function

In this section, I will describe how to use the Power Automate length() function by creating an Instant cloud flow that will trigger manually and in Automated cloud flow using a SharePoint list.

Example:- 1 [Power Automate length() function Manually]

Let’s see how the Power Automate length() function expression determines the number of elements in a provided array.

In this example, I wanted to determine the number of elements that an array consists of [Array = “Washington”,”Minnesota”, “Texas”, “New York”, “California“] by using the length() function.

Then, the result from the Power Automate length() function will give the output as 5, which defines the number of items in it.

Power Automate length() Function syntax

To work around this, follow the below-mentioned steps:

1. Open the Power Automate Home page -> In the left navigation of the Power Automate Home page, click on + Create -> Select the Instant cloud flow -> Provide the flow name and choose the trigger’s flow (Manually trigger the flow) -> Click on Create button.

2. In this step, I have taken the ‘Initialize variable’ flow action to store the value of an array. Ensure to provide the following details:

  • Name: Give the name of the initialized variable manually.
  • Type: Select the type of the variable as Array.
  • Value: Here, I have given [“Washington”,”Minnesota”, “Texas”, “New York”, “California“] as value.
How to use Power Automate length() Function

3. Then, add a Compose flow action to determine the number of elements in an array. I will take the length() function expression in the inputs section.

  • Inputs: Select field -> Click Expression -> Insert the code -> Then click on OK.
length(variables('Countries'))
Power Automate length() function expression

4. Once the flow is created, select Save and Test -> Then test it Manually. The compose flow action will display the output according to the length() function expression below.

  • The return value of the Power Automate length() function is 5, which defines the number of elements in an array.
Power Automate length() function format

This is how to use the length() function in Power Automate to determine the length of elements an array consists of.

Example:- 2 [Power Automate length() function using SharePoint list]

I will demonstrate one more example of the Power Automate length() function using a SharePoint list in an Automated cloud flow.

To implement this, I have taken a SharePoint list named User Registration with different types of columns and their datatypes as shown in the table below:

Column NameDatatype
User NameA single line of text
User Registered IDA single line of text
Email AddressSingle line of text
length() function in Power Automate

In this example, I want to determine the number of characters of the string, i.e., from the SharePoint list column [User Registration ID].

Using the Power Automate length() function, it returns the length of the characters from a string [UID7418523 => 10]. Whereas 10 defines the number of characters that the provided string has.

Usage of Power Automate length() function

To achieve this example, go through the below-mentioned steps:

1. Navigate to https://make.powerautomate.com in your browser in your browser, click + Create -> Select the Automated cloud flow -> Provide the flow name, and choose the trigger’s flow (When an item is created) -> Click on the Create button.

In the trigger, provide the details like:

  • Site Address: Provide the specific SharePoint site address.
  • List Name: Select the specific name of the SharePoint List.
length() function expression using Power Automate

2. Next, add a Get item flow action to get all the column values of a particular item created. Set the following properties below:

  • Site Address: Provide the specific SharePoint site address.
  • List Name: Select the name of the SharePoint List.
  • Id: Provide the SharePoint item ID from dynamic content.
Microsoft Power Automate length() function

3. Then, add an Initialize variable flow action to initialize the SharePoint list column that can be used during the flow. Provide the required details as shown below:

  • Name: Here, I have provided the name of the initialized variable as User Registration ID.
  • Type: Select the variable datatype as String.
  • Value: I have taken a ‘User Registration ID’ column from dynamic content here.
Microsoft Power Automate length(0 function expression

4. At last, take a Compose flow action to give the length() expression to determine the length of a given string.

Inputs: Select field -> Click Expression -> Insert the code -> Then click on OK.

When applied to a string, the length() function returns the number of characters.

length(variables('User Registration ID'))
How to use Power Automate length() function format

5. Now, the flow is ready. It’s time to Save and run the flow. Click on Test. Here, add or modify an item to the SharePoint list.

Power Automate length function using SharePoint list

6. When the flow runs successfully without any errors, the compose flow action will display the return value from the length() expression as shown below:

  • The output of the Power Automate length() function will be 10, which defines the number of characters in a string.
Power Automate length() function using SharePoint list

This is how to use the Power Automate length() function to calculate the length of a string using values from the SharePoint list.

Conclusion

I trust this Power Automate tutorial helped you to achieve your goal of determining the length of a string or an array. In this guide, I have covered the following topics:

  • Introduction to the Power Automate length() function
  • Power Automate length() function syntax
  • Power Automate length() function using Instant cloud flow [Array]
  • How to use the Power Automate length() function using an Automated cloud flow [using SharePoint list]

Also, you may like some more Power Automate tutorials: