When working with Power Apps applications, we should use a list of functions to build more responsive and attractive apps. One of the most important and easy functions is the Len() function, which determines the length of a string.
In this tutorial, I will explain what the Power Apps Len function is and its syntax. Then, we will see how to get the Power Apps length of string and how to work with the Power Apps length of collection.
Also, I will show you how to get the Power Apps count specific characters in string and Power Apps text input max length.
Power Apps Len Function
The Len function in PowerApps returns the number of characters in a string. It’s particularly useful when you need to validate input length, manipulate strings based on their length, or display the length of a string to the user.
When you specify a single string as the argument, the return value is a number. Likewise, if you specify a blank or empty string, the Len returns Zero(0).
PowerApps Len Syntax
Below are the Power Apps len function syntaxes:
Syntax – 1:
Len( String )
Where,
- String = This is Required. Specify the string to measure
Syntax – 2:
Len( SingleColumnTable )
Where,
- SingleColumnTable = This is Required. Specify the single-column table of strings to measure
Power Apps Length of String
To get the length of the string in Power Apps, follow the different examples below. Such as:
Example-1:
In Power Apps, there is a Text input control and a Text label control. The text label control has a string [“Welcome To Power Apps”]. Now, I would like to find out the length of the string and display the result on the text label control.
Have a look at the below screenshot for the output.
To achieve it, follow the below steps.
1. On the Power Apps Screen -> Insert a Text input control and set its Default property to the code below.
Default = "Welcome To Power Apps" //You can change the text as per needs
2. Next, insert a Text label control and set its Text property as:
Text = "Length of the Text: "&Len(txt_String.Text)
Where,
- txt_String = Power Apps text input control name
3. Once your app is ready, Save, Publish, and Preview the app. The text label control displays the length of the string value [Number] based on the text input string value.
4. Similarly, if you pass the empty string in the text label, then the Len function will return the “Zero value,” as shown below.
Note:
When an empty string is passed within the text label, the Len function will return a “Zero” value. However, if spaces are present within the inverted commas, it is counted as one character.
Example-2:
I have a SharePoint Online list named “User Credentials” and this list contains the below fields.
Column Name | Data Type |
Username | It is a default single line of text |
Password | A single line of text |
Now, I would like to get the length of each single line of text field values [Password] and display the result on the Power Apps dropdown control.
To do so, set the Dropdown’s Items property using the code below.
Items = Concatenate(
'User Credentials'.Password,
" - ",
Len(
ShowColumns(
'User Credentials',
"Password"
)
)
)
Where,
- ‘User Credentials’ = SharePoint Online list
- Password = SharePoint list text field
Now, Preview the app. Once you expand the dropdown control, it will count each character of the SharePoint list text value and display the result as a number.
Output:
Example-3:
In the same way, if you want to count the characters of dropdown control manual items [Single column string values], you can follow the code below.
Items = ["John", "Henrita mullar", "Pattie", "Johannal"]
Where,
- “John”, “Henrita mullar”, “Pattie”, “Johannal” = Power Apps dropdown values
Power Apps Length of Collection
To get the Power Apps length of the collection, follow the scenario below.
Scenario:
Suppose there is a Power Apps collection [colBooks], and you want to count the total number of records in the collection. That means you will measure its length.
For that, insert a Text label control and apply the below formula on its Text property as:
Text = "Length of Collection: " & CountRows(colBooks)
Where,
- colBooks = Power Apps collection name
This way, you can get the Power Apps length of the collection.
Power Apps Count Specific Characters in String
To count the specific characters in a string, follow the below steps.
1. On the Power Apps Screen, insert a Text input control and set its Default property as:
Default = "Microsoft Power Platform"
2. Now, I would like to count the “o” character value and display the result on the text label control. For that, set the Text label’s Text property using the code below.
Text = CountRows(Split(txt_String.Text,"o"))-1
3. The output below shows that the letter ‘o’ contains 4 characters in the string value.
Power Apps text input max length
In this example, I would like to make the text input field length should be 14 characters. This means the user has to input only 14 characters in that field.
If the text input field contains more than 14 or fewer than 14 characters, the button will disable mode, and the text label will display a warning message, such as “Text should be exactly 14 characters. “
Have a look at the below screenshot for the output.
To work around this, follow the below steps.
1. On the Power Apps Screen -> Insert a Text input control and set its Default property as blank and set its BorderColor property as:
BorderColor = If(
Len(txt_AddText.Text) = 14,
RGBA(
0,
18,
107,
1
),
Color.Red
)
Where,
- txt_AddText = Power Apps text input control name
2. Next, add a Text label control and set its Text and Visible properties, as shown below.
Text = "Text should be exactly 14 characters"
Visible = Len(txt_AddText.Text) <> 14
3. Finally, insert a Button control and set its DisplayMode property as:
DisplayMode = If(
Len(txt_AddText.Text) = 14,
DisplayMode.Edit,
DisplayMode.Disabled
)
4. Save, Publish, and Preview the app. When you enter the character until 14, the button will be in edit mode and clickable, and the warning message will be disabled. Otherwise, the button control is in disable mode, and the warning message will be enabled, as in the screenshot below.
This is how we can work with the Power Apps text input max length.
Also, you may like:
- Create Collection in Power Apps
- Cascading Dropdown in Power Apps
- Power Apps Lower, Upper, and Proper Function
- Power Apps Value Function
- Power Apps CountIf Function
- Power Apps Notify Function
From this Power Apps tutorial, we learned in detail information about the Power Apps Len function. Including:
- Power Apps length of string
- Power Apps length of collection
- Power Apps count specific characters in string
- Power Apps text input max length
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com