Len function in Power Apps
The Len powerapps function returns the length of a string of text. We can give a single string or a single column table as an argument to this function. If we specify a blank string, Len returns 0.
1. Single String
If we specify a single string as the argument, the return value is the length as a number.
Power Apps Syntax Len(String)
The function has the one required parameter:
• String - Required. The string to measure.
Example: For the examples in this section, the data source is a text-label control that's named Label1 and that contains the string "Ashish Goel is a developer".
Power Apps Formula
//Here Label1 is the name of the Text label control.
The expression Len(Label1.Text) returns the length of the text that is currently displayed in the Label1 control. The Len() function is a built-in function that returns the number of characters in a string.
Power Apps Formula
//Here, we have taken an empty string
The above formula measures the length of an empty string.
But if we take spaces in between the inverted commas it is counted as one character.
Power Apps Formula
//Here, we have taken two spaces between inverted commas
2. Single Column Table
If we specify a single-column table that contains strings, the return value is a single-column table with a Value column that contains the length of each string.
Power Apps Syntax Len(SingleColumnTable)
The function has the following parameter:
• SingleColumnTable - Required. A single-column table of strings to measure.
Example: We can use any table, for now we are using a sharepoint list as a data source. We have a list in sharepoint called “My Users List”.
Step 1: Add this Data source in the Power Apps.
Step 2: Add a drop down control and set its Items property to the following powerapps formula.
Power Apps Formula
Here, field_1 is the internal column name of “Teacher Name”.
The above powerapps formula returns a single-column table with a Value column containing the following values: 8, 13, 10….As Sushmita contains eight characters, and Anjali Sharma contains thirteen characters (including space).
Step 3: We can give any single column table.
For example:
Power Apps Formula
The function returns a single-column table with a Value column containing the following values: 7, 11, 5, 0.