The StartsWith is a handy function that allows you to check if a text string starts with another.
It follows a simple pattern.
- 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.
- 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.
- 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.
- If you’re using a variable or any other data source to compare, use the Trim function to remove trailing spaces.
- Always check the type of the comparison, in case you’re using variables; otherwise, you may end up with errors in your Power App.
- 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.
- 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.
Back to the Power Apps Function Reference