Searching data–What you need to know about case sensitivity

In this post, we'll look at how PowerApps behaves when it comes to case sensitivity. This is important because it can affect the results of comparisons and searches. Here are the top three things you should know about case sensitivity. 

1 Beware when making string comparisons

String comparisons ARE case sensitive.  Here's an example of where this can be a problem. The formula beneath attempts to apply conditional formatting to a data card. If the gender equals "male", the fill color of the card should be AliceBlue.

As the screenshot shows, the fill color of the card is white. The comparison fails because:

"Male" = "male" -> false

To work around this issue, we can convert the value that we want compare with the Lower function, and carry out our comparison against a lower case string. So in this example, our comparison operator would look like this:

If(Lower(ThisItem.Gender) = "male",
Color.AliceBlue,
Color.Whilte
)
Another common scenario where this occurs is when app builders want to compare email addresses.

2 Column Names are Case Sensitive

Column names ARE case sensitive. As the screenshot beneath shows, IntelliSense displays a warning when we use the incorrect casing for a column name.


As I explain in the link below, I believe this behavior stems from the case sensitive nature of JSON.

3 Searches are Case Insensitive

For SharePoint and most data sources, any searches that we carry out with the Filter and Search functions are NOT case sensitive. To illustrate, here's a standard search screen that uses the Filter function, based on a SharePoint data source. Here, we can see that a search value of "tiM" matches "Tim".

4 SQL Server DataSources are an Exception

Although searches with Filter and Search are generally NOT case sensitive, searches against SQL Server data sources CAN be case sensitive, depending on the collation sequence of the database. In the post beneath, I explain this behavior in a bit more detail.


(Note that this behavior can also apply to on-premises SharePoint data sources that are backed by a SQL Server with a case sensitive collation).

To check the collation sequence of SQL Server, here are the TSQL commands that we can run:

-- 1 This returns the server collation 
SELECT SERVERPROPERTY('COLLATION')

-- 2 This returns the collation of a specific database
SELECT collation_name
FROM sys.databases
WHERE name = 'your_database_name'

-- 3 This returns the collation of a table
SELECT COLUMN_NAME, COLLATION_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'your_table_name' AND CHARACTER_SET_NAME IS NOT NULL
The collation sequence will look something like this:  SQL_Latin1_General_CP1_CS_AS

The 'CS_AS' part of this indicates a case sensitive, accent sensitive collation sequence.

So what can we do if we have a case sensitive SQL data source and want to carry out case insensitive searches from PowerApps? One way is to apply the Lower function against the source field and to match against a lower case criteria value. 

Filter(EmployeeTable, Lower(Firstname) = "tim")

However, the big disadvantage of this technique is that it's non-delegable and it won't return accurate results if our source data exceeds 2000 rows. Therefore, a better technique is to create a SQL View and to cast the fields we want to search against to a non case sensitive collation. From within PowerApps, we can then Filter/Search against the view that we created. Here's an example of how such a view definition would look like:

SELECT id,
       CAST(Firstname AS NVARCHAR(MAX)) COLLATE SQL_Latin1_General_CP1_CI_AS Firstname,
       CAST(Surname AS NVARCHAR(MAX)) COLLATE SQL_Latin1_General_CP1_CI_AS AS Surname,
       Salary,
       DateOfBirth
FROM dbo.Employee
A useful tip is that we can 'invert' this technique. So if our source database is case insensitive and we want to carry out case sensitive searches from within PowerApps, we can create a view and cast our fields to a case sensitive collation (such as SQL_Latin1_General_CP1_CS_AS).

Conclusion

In conclusion, string comparisons and column names are case sensitive in PowerApps. Searches can be case sensitive or case insensitive, and this depend on the underlying data source.

Related posts

Data - How to remove trailing comma all rows in a table
February 20, 2025
Data - How to find the common rows from 3 or more collections
October 06, 2024
Data - How to show the distinct rows from 2 data sources or collections
February 26, 2024
Data - How to implement circular rotational date sorting
February 21, 2024
Bug - What to do when the data section of the Power Apps Maker portal doesn't work
June 18, 2023
Data - Combine columns from separate tables into a single table
October 13, 2022
Formula - Transposing/converting rows to columns- an almost impossible task?
September 23, 2021
Data - How to rename field names in a record
July 14, 2021
Data - How to hide duplicate rows in a gallery / show distinct multiple columns in a gallery
July 09, 2021
Data - Retrieving news/forum/blog articles with RSS
June 26, 2021
Data - How to sort by partial numbers in a text field
June 23, 2021
Data - How to return the last record from a table
June 19, 2021
Data - How to create bulk test/dummy records with random values
June 18, 2021
Data - 3 things you should know before using the MySQL or PostgreSQL connectors
May 11, 2021
Data - A walkthrough of how to migrate the data source of an app from Excel to Sharepoint
April 26, 2021
Data - How to enforce unique values (or prevent duplicate values) in one or more columns
April 19, 2021
Data - How much mobile data does Power Apps consume? What ways can we minimise this?
March 28, 2021
Data - How to save and retrieve Google calendar entries
March 14, 2021
Data - How to save and retrieve Google contacts
March 10, 2021
SQL - Caution! This is how users can hack shared SQL connections
January 23, 2021
SharePoint – 2 Mistakes to avoid when importing Excel data
January 10, 2021
SQL - Don't let this DateTime bug catch you out!
January 05, 2021
Settings - What's the purpose of the "Explicit Column Selection" Setting?
January 04, 2021
SQL Server for Beginners Part 3 - Installing On-Premises Gateway
January 24, 2019
SQL Server for Beginners Part 2 - Installing Management Studio
January 14, 2019
SQL Server for Beginners Part 1 - Installing SQL Server
January 04, 2019
Images - How to create images that can change depending on data
November 09, 2018
Excel - Reasons NOT to use Excel as a data source
September 25, 2018
SharePoint - What you need to know about Filtering Data
September 16, 2018
Formulas - Generating Row Numbers
April 05, 2018