Power Apps Len Function | Power Apps Length Of String

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.

powerapps length of string

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
len powerapps

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
powerapps len function

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.

power apps len function

4. Similarly, if you pass the empty string in the text label, then the Len function will return the “Zero value,” as shown below.

powerapps get length of text

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.
power apps get length of text

Example-2:

I have a SharePoint Online list named “User Credentials” and this list contains the below fields.

Column NameData Type
UsernameIt is a default single line of text
PasswordA single line of text
powerapps len

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
powerapps string length

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:

powerapps count characters in string

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 text

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.

powerapps length of collection

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 length of 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"
Power Apps count specific characters in string

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.

powerapps count specific characters in string

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.

PowerApps text input max length

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
Power Apps text input max length

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
power apps string length

3. Finally, insert a Button control and set its DisplayMode property as:

DisplayMode = If(
    Len(txt_AddText.Text) = 14,
    DisplayMode.Edit,
    DisplayMode.Disabled
)
power apps string max length

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.

powerapps text input character limit

This is how we can work with the Power Apps text input max length.

Also, you may like:

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
>