October 16, 2024

The StartsWith is a handy function that allows you to check if a text string starts with another.

Usage

It follows a simple pattern.

  1. Text
  2. Start Text

It’s simple, but you should know some things so as not to get some nasty surprises.

The comparison is case insensitive:


StartsWith("Hello","h")

# Returns: true

It considers the strings as is, so you should be careful with trailing spaces:


StartsWith("Hello"," Hello")

# Returns: false

To properly test, you should remove the trailing spaces. To do that you need to use the Trim function.


# You need to use the Trim function to remove the spaces

StartsWith("Hello",Trim(" Hello"))

# Returns: true

Don’t forget that you’re only checking if the string starts with another text string. If the string is in the middle or end of the text string, then it always returns false.


StartsWith("Hello","Oh Hello There")

# Returns: false

In another case, you need to be aware of it’s compared with an empty string. If you’re comparing with a variable this issue will be hidden, but you may have invalid results:


StartsWith("Hello","")

# Returns: true

One could argue that this should not be the case, but that’s the way Microsoft defined it, so you should be aware of it.

Limitations

  1. This function is only delegable if you’re using text strings and only in Dynamics 365, Common Data Services, and SQL Server. If you don’t know what this is, please check my article on delegation and my reference table of the data sources where Filter will be delegable if not only the first 500 values (default value up to 2000) are displayed.

Recommendations:

  1. Since the comparison is case insensitive, be careful when using this function. Sometimes you would want to consider “Hello” and “hello” different strings but, in this function, they will be the same.
  2. If you’re using a variable or any other data source to compare, use the Trim function to remove trailing spaces.
  3. Always check the type of the comparison, in case you’re using variables; otherwise, you may end up with errors in your Power App.
  4. Don’t try to nest because you’ll get the error in the formulas since the StartsWith will return a true/false, and that’s not a valid string.

Localization

  1. Please note that formulas may have localization-based differences. For example, you should write “StartsWith(10,3) “ with “,” separating each of the arguments, but if set your regional settings to Portugal, you should use “;” instead.

Sources:

StartsWith function in PowerApps

Back to the Power Apps Function Reference

Photo by Gia Oris on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon