Ignore case sensitive for given word - google-sheets

I have a search Query where I'm looking for values in my table. And I want to dynamically search for a value, for example, "AMAZON".
="select B, C, L, E, O, P, Q WHERE B >= date '"&TEXT(A2; "yyy-mm-dd")&"' and B <= date '"&TEXT(B2; "yyy-mm-dd")&"' and L matches '.*"&C2&".*' and E LIKE '%"&D2&"%'"
"C2" is my empty cell, for searching for a string. I, for example, input "amazon" into "C2"
My problem is that is doesn't return anything as in my table it's written "AMAZON" or probably "Amazon" so it won't find anything as I have a direct link to "C2"I couldn't figure out that way of phrasing the regular expression to ignore the case sensitive.
It would return anything as soon as I write "AMAZON" in "C2".
Goal:
I want to make it non case sensitive. Cause at the moment my formula won't print anything as soon as I don't write it in initial letters.

Please try lower in all cells you reference as well as all depending, returning columns.
So your formula would be:
="select B, C, L, E, O, P, Q WHERE B >= date '"&TEXT(A2; "yyy-mm-dd")&"' and B <= date '"&TEXT(B2; "yyy-mm-dd")&"' and lower(L) matches '.*"&lower(C2)&".*' and lower(E) LIKE '%"&lower(D2)&"%'"

Related

In Google Sheets, how can I find the value in a column of a row when you know the lookup column name and result column name?

I have a Sheet1 with data like this:
one
two
three
four
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
I have Sheet2 with data like this:
alpha
value
c
k
g
c
For each row in Sheet2, I want to look up Sheet2.alpha in Sheet1.three and return the value of Sheet1.one. I want to do this by putting an array formula in B2.
So, the expected result is:
alpha
value
c
a
k
i
g
e
c
a
I can use the new Google Sheet formulas they just released -- except named ranges. I feel like there is some clever trick using them, but I can't come up with it.
BYROW() and XLOOKUP() are your friend in this case.
=BYROW(A2:INDEX(A2:A,COUNTA(A2:A)),LAMBDA(x,XLOOKUP(x,Sheet1!C2:C,Sheet1!A2:A,"Not Found")))

Moving Calendar Events around Google Sheets

I have a series of Google Calendars I am subscribed to. In my main Spreadsheet that I do most of my work out of, I have a launch page that I want to have the events pulled for today and tomorrow from each Calendar.
The data is pulled from Google Calendar and put into a hidden sheet called Under The Hood. I then use the following query to try and pull the ones that are A) relevant and B) Happening today (or tomorrow, two different queries).
Today's Events
=QUERY('Under The Hood'!M4:O13, "select M, N where M contains 'P/U' or M contains 'D/O' and toDate(O) contains 'toDate(TODAY())'",0)
Tomorrow's Events
=QUERY('Under The Hood'!M4:O13, "select M, N where M contains 'P/U' or M contains 'D/O' and O contains date'" & TEXT(TODAY()+1,"yyyy-mm-dd")&"'",0)
Both of these queries give me the same partial list of the events from tomorrow and the day after tomorrow.
your formula should be:
=QUERY('Under The Hood'!M4:O,
"select M,N
where M matches '.*P/U.*|.*D/O.*'
and O contains date '"&TEXT(TODAY()+1, "yyyy-mm-dd")&"'", 0)
Solution
Your logic statement right now is this:
M contains 'P/U' or (M contains 'D/O' and O contains date'" & TEXT(TODAY()+1,"yyyy-mm-dd")&"')
(Explicit parenthesis are inserted)
This means that it will return true by just checking that M contains 'P/U'.
You should formulate your logic statement in a way that will check:
M = 'P/U' and O = 'date you want' or M = 'D/O' and O = 'date you want'
To do this just wrap the logical statements on the M columns inside the parenthesis as recommended by the documentation:
You can join multiple conditions using the logical operators and, or, and not. Parentheses can be used to define explicit precedence.
=QUERY('Under The Hood'!M4:O13, "select M, N where (M contains 'P/U' or M contains 'D/O') and O contains date '"& TEXT(TODAY(), "yyyy-mm-dd")&"'",0)
Reference
Query Language

Compare dates, if date is most recent, then return adjacent cell data

I'm working on a Google Sheets document for tracking covid-19 cases reported in nursing homes, institutions, etc. I'm heavily employing formulas across my sheets to minimize the number of ways my coworkers can accidentally screw up the numbers. I've made a copy of the pertinent sheet here so you can take a look.
I've run into a problem, though. So, on one sheet, we have all records of articles that mention statewide case/death numbers. We want to continue to keep track of those, but also be able to easily retrieve/display the most recently reported numbers for any given state. Essentially what I'm trying to do is:
Delimit search to only rows where column A contains a specific state (AL, FL, GA, etc)
Of those rows, compare the date values in column B, identify the most recent one
Once the most recent entry for a given state is found, then output the value of column E (or D, or C, doesn't matter, I assume that changing that part will be straightforward enough)
I got as far as =MAXIFS(B3:B100, A3:A100,"CT") but I'm not sure syntactically what to tell it next, or if I'm going about this the right way.
Update: We have gotten closer with =query(A1:E,"select A, C where A = 'CO' and B = date '"&TEXT(DATEVALUE(max(B2:B)),"yyyy-mm-dd")&"'",1) and =query(A1:E,"select A, C, D, E where A = 'CO' and B = date '"&TEXT(DATEVALUE(max(B2:B)),"yyyy-mm-dd")&"'",1), but in practice this only returns rows with the absolute most recent date, rather than the most recent date relative to which state's dataset you're looking at.
Need to be able to display the relative most recent entry per state.
UPDATE UPDATE: I figured it out! (sheet name added because I'm referencing it from a different sheet)
=query('Statewide Reported'!A1:E,"select A, B, C, D where A = 'NJ' and B = date '"&TEXT(maxifs('Statewide Reported'!B3:B100, 'Statewide Reported'!A3:A100, "NJ"),"yyyy-mm-dd")&"'",1)
Thanks so much for pointing me in the right direction!!
You could use query() to select the number of deaths for CO matching the most recent date using this formula:
=query(A1:E,"select A, C where A = 'CO' and B = date '"&TEXT(DATEVALUE(max(B2:B)),"yyyy-mm-dd")&"'",1)
If you want deaths, cases, and total affected you can use:
=query(A1:E,"select A, C, D, E where A = 'CO' and B = date '"&TEXT(DATEVALUE(max(B2:B)),"yyyy-mm-dd")&"'",1)
Update:
This will find the max date for a specific State (CO):
=query($A$1:$E,"select A, C, D, E where A = 'CO' and B = date '"&TEXT(maxifs($B$2:$B,$A$2:$A,"CO"), "yyyy-mm-dd")&"'",1)
Or if you want to reference a State name in a cell (H1) you can use this formula:
=query($A$1:$E,"select A, C, D, E where A = '"& $H$1 &"' and B = date '"&TEXT(maxifs($B$2:$B,$A$2:$A,$H$1), "yyyy-mm-dd")&"'",1)

Google Sheets date query won't work on specific columns

I have data that I'm importing from Salesforce, and I'm using query functions to find all rows where any of the columns has a date in a given range. Here's an example of the data:
The query that's not working is:
=query('Salesforce Data'!A2:C,"SELECT A,C WHERE C >= date '"&TEXT(DATEVALUE($A$1),"yyyy-mm-dd")&"' AND C < date '"&TEXT(DATEVALUE($B$1),"yyyy-mm-dd")&"'")
I'm using the same query except in one case, it's looking at dates in column B, and in the other, it's looking at the dates in column C. The column B version works, the column C version does not. I have verified that there is at least one date in column C that falls in the range, so it should not be an issue of no data, as the error suggests:
I've looked over data formatting, and there is no difference between columns B and C in that regard. These are the same types of field in Salesforce as well, so I would not expect a difference in formatting. I tried manually changing the first value in column C to a date (that was an obvious difference between the columns), but that also didn't work.
After a lot of trial and error, I found the issue: it seems that Google Sheets classifies the column of data based on what the majority of the cells are. So, even though both columns B & C have some cells with valid dates and some with a - signifying null, column B has more dates than strings, but C has more strings than dates, so date compare queries won't work on column C at all.
My solution for now is to add a formula sheet to transform all of the null values, -, into a date that won't mess with my query, 1/1/1970:
Example formula:
=IF( OR('Salesforce Data'!C2="-",'Salesforce Data'!C2=""), date(1970,1,1), 'Salesforce Data'!C2)
Another solution would be to edit the data source, but this solution will work entirely within sheets.
Also note, I dragged this formula down far below where I needed, just in case, make sure that if you have a text column (like my column A), you replace empty values there with junk text of some sort. At first I replaced with 0 and then my text column wasn't picked up by the query.
try:
=ARRAYFORMULA(QUERY(TO_TEXT('Salesforce Data'!A2:C),
"select Col1,Col3
where Col3 >= date '"&TEXT(A1, "yyyy-mm-dd")&"'
and Col3 < date '"&TEXT(B1, "yyyy-mm-dd")&"'", 0))
Thank you thank you so so much. This thread helped me a lot.
I have used these from this thread. Someone may need in future:
"select A, B, C, G, H, J where I='"&TEXT($A$2, "dd-mmm-yyyy")&"'"
"select B, C WHERE F= date '"&TEXT(DATEVALUE($A$2),"yyyy-mm-dd")&"'"
"select A, B, C, G, H, J where I='"&TEXT($A$2, "dd-mmm-yyyy")&"' or I='"&TEXT($A$2, "d-mmm-yyyy")&"'"

Query for does not contain

I have a sheet that queries three others in the same document and selects a bunch of rows where the column G contains no. Ideally I would prefer it be a query that does not contain the word yes or Yes. I have tried using all of the following mechanisms:
where not (G contains 'yes')
where not (G contains 'es')
where not (G matches '[yY]es')
where G contains 'no'
and no matter which one I pick I run into one of two issues:
Issue number 1 is that part of the query fails because only one of the values is present. Ie there is a Yes but not a yes, which results in the output of #VALUE. This is problematic because I am trying to allow for both scenarios since I cannot control what the end user of this will input into the sheet.
or Issue number 2 which is far worse. When I specifically say select all where G contains no one of the rows that displays contains a yes. Note that this also occurs with some of the other mechanisms as well but I would think specifically saying no should prevent this and does not.
The full query I am using is:
=ARRAYFORMULA({QUERY(Sheet1!A2:I500, "Select A, B, C, D, E, F, G, H, I where G contains 'no'");(QUERY(Sheet2!A2:I500, "Select A, B, C, D, E, F, G, H, I where G contains 'no'"));(QUERY(Sheet3!A2:I500, "Select A, B, C, D, E, F, G, H, I where G contains 'no'"))})
What am I doing wrong here?
The specific issue here was the query range. But the actual answer to the question (how do I query not like / not contain) is different.
I couldn't find this in the query reference but the answer is to put not straight after the where:
"Select A, B, C, D, E, F, G, H, I where not G contains 'yes'"
To further improve, you should lower(G) to make it exclude 'Yes' and 'yes'
The problem is the query range. It starts a Row2 which contains data rather than labels. By default the first row of a query is treated as heading for the output (so selection criteria are not applied to it). Hopefully a fix is just to adjust the query to exclude headings. Please try:
=QUERY(Sheet1!A2:I500,"Select * where G = 'no'", 0)

Resources