5

I discovered (when answering this question) that string comparison in filter is case insensitive: the formulas =filter(A:A, B:B = "Yes") and =filter(A:A, B:B = "YES") have the same output.

Apparently, this is true generally for string comparison in Google Sheets: ="Y"="y" returns TRUE, and so does its equivalent =eq("Y", "y").

This is convenient sometimes, but what to do when I want to filter rows by case-sensitive string equality?

2 Answers 2

4

Short answer

Use REGEXMATCH(text, regular_expression) instead of = or EQ(value1,value2) to set the conditions for FILTER(range,condition1,[condition2, ...])

Demostration

Data source

+---+---------+---------+
|   |    A    |    B    |
+---+---------+---------+
| 1 | Field 1 | Field 2 |
| 2 | Yes     | A       |
| 3 | YES     | B       |
| 4 | no      | C       |
| 5 | No      | D       |
| 6 | NO      | E       |
| 7 | yes     | F       |
+---+---------+---------+

Formula in D1

=FILTER(A2:B7,REGEXMATCH(A2:A7,"^yes$"))

(The word is placed between ^ and $, so that the entire cell content is required to match it.)

Result

+---+-----+---+
|   |  D  | E |
+---+-----+---+
| 1 | yes | F |
+---+-----+---+
1
  • @404: Thanks. I updated the formula.
    – Rubén
    Mar 29, 2016 at 22:32
4

Short answer

Instead of FILTER use QUERY

Demostration

Data source

+---+---------+---------+
|   |    A    |    B    |
+---+---------+---------+
| 1 | Field 1 | Field 2 |
| 2 | Yes     | A       |
| 3 | YES     | B       |
| 4 | no      | C       |
| 5 | No      | D       |
| 6 | NO      | E       |
| 7 | yes     | F       |
+---+---------+---------+

Formula in D1

=QUERY(A1:B7,"select B where A = 'yes'",1)

Result

+---+---------+
|   |    D    |
+---+---------+
| 1 | Field 2 |
| 2 | F       |
+---+---------+
2
  • Makes sense, but is not a completely satisfying answer. There are things that filter does and query cannot do, like handle columns with both strings and numbers.
    – user79865
    Mar 29, 2016 at 21:13
  • @404: The question doesn't mention that handling strings and numbers features are relevant, by the other side, numbers are not case sensitive ;).
    – Rubén
    Mar 29, 2016 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.