Skip to main content

How to Count Characters in Power Apps with Len

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Len returns how many characters a piece of text has, spaces included. It's the tool for checking a maximum length before you save something, showing "123 of 4,000 characters", and finding spaces you can't see. One formula, one number.

Syntax​

Syntax
Len( Text )

It returns a number. Given a single-column table of text instead, it returns a table of lengths (Len reference).

Prerequisites​

  • A canvas app with a Text control to try formulas in. The example uses a Text control on the Career Development Plan app's Home screen, from Part 4 of the series.

Step 1: Count the Characters in Some Text​

Text control → Text
Len(" Sales Engineer ")

The formula bar with Len of a text with leading, inner and trailing spaces, the preview strip reading 21 with Data type number

"Sales Engineer" is 14 characters; the other 7 are spaces. The preview strip collapses runs of spaces when it shows text, so Len is the reliable way to see them. How to Remove Extra Spaces in Power Apps with Trim and TrimEnds uses it to compare the two functions.

Step 2: Check a Maximum Length​

Before saving text to a column with a limit, check it:

Button → DisplayMode (example)
If(Len(txtResponse.Value) > 4000, DisplayMode.Disabled, DisplayMode.Edit)

Or show a counter next to the box:

Text control → Text (example)
Len(txtResponse.Value) & " of 4,000 characters"

The Career Development Plan series uses this in Part 6, to count the characters in a response (How to Limit Text Length and Show a Character Count).

Empty Text​

Microsoft's Blank and IsBlank reference notes that Len returns zero for an empty string, "". To test whether something is empty or blank, IsBlank covers both; see IsBlank vs IsEmpty in Power Apps.

Common Mistakes​

MistakeWhat happensDo this instead
Trusting the preview strip to show spacesIt collapses themUse Len
Checking length after savingThe save may already have failedCheck before, in DisplayMode or the save formula
Using Len to test for blankWorks for "", but less clearUse IsBlank

FAQ​

Does Len count spaces?​

Yes, every character, including spaces.

Can I count the rows of a table with Len?​

No. Use CountRows for rows; Len on a table returns the length of each text value.

Conclusion​

Len(text) returns the number of characters, spaces included. Use it for length limits and counters, and to see spaces the preview strip hides.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.