Canvas Apps Expressions

Case sensitivity of string comparisons

Different types of string comparisons work differently - some are case sensitive while some are case insensitive. A question came up on the Power Apps community (yes, almost all of them start there!) where someone wanted to implement a login process for which the string comparison had to be case sensitive, as expected.

Here are the assumptions for this example:

  • The data source used in this example is a CDS entity called Users (this could be anything e.g. a SharePoint list)
  • TextInput is the text input control where the user is expected to type in the password
  • If the password entered by the user is the correct one, a Successful login message will be displayed (if not, then Unsuccessful login)

A couple of options that were tried by the original poster:

  • Filtering to check if there is a record with a password that is same as the password entered by the user:
    If(CountRows(Filter(Users, Password = TextInput.Text))=1, Set(loginConfirmation, "Successful"), Set(loginConfirmation, "Unsuccessful"))
  • LookUp to check if there is a record with a password that is same as the password entered by the user:
    If(!IsBlank(LookUp(Users, Password = TextInput.Text)), Set(loginConfirmation, "Successful"), Set(loginConfirmation, "UnSuccessful"))
    

Filter and LookUp are not case sensitive whereas a simple string comparison is case sensitive. Based on this, the following options worked:

  • Using a string comparison by fetching the user's password and comparing it with the password entered by the user:
    If(TextInput.Text = LookUp(Users, Name = "Hardit Bhatia").Password, Set(loginConfirmation, "Successful"), Set(loginConfirmation, "Unsuccessful"))
  • Using a string comparison by fetching and storing the user's password in a variable and then comparing it with the password entered by the user:
    Set(userPassword = LookUp(Users, Name = "Hardit Bhatia").Password); If(TextInput.Text = userPassword, Set(loginConfirmation, "Successful"), Set(loginConfirmation, "Unsuccessful"))

One more option that I wanted to cover is Search. This, by default, is not case sensitive. It is ideal for use cases like searching for users by typing in the name. Here is an example (where cr564_name is the column name):

If(CountRows(Search(Users, TextInput.Text, "cr564_name"))=1, Set(searchConfirmation, "Successful"), Set(searchConfirmation, "Unsuccessful"))

Thus, to summarize, for most databases, Search, LookUp, and Filter are not case sensitive whereas string comparisons are. If we need to modify the behavior of any of these, functions like Lower, Upper, and IsMatch can help.

Have fun! Get addicted!

1 thought on “Case sensitivity of string comparisons”

Leave a Reply