Moving Calendar Events around Google Sheets - 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

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")))

Countifs N Count across multiple criteria (in data validations) but not returning zero if data validated cell is blank

Trying to set up a formula where I can pull N counts based off multiple criteria including a date range. A typical Countif formula could work in theory:
=countifs(D2:D, J2, F2:F, J3, E2:E, J4, G2:G, J5, C2:C, ">="&TODAY()-7, C2:C, "<="&TODAY())
However, the problem I am facing is I want to be able to still pull the N count even if I leave one or more data validated cells the formula is pulling off of blank. In order to pull anything, you have to select one of the 4 data validated options. As you select more, the data gets more granular. Currently if I leave one cell blank, I then get a zero on the return. Need that not to happen
Any thoughts on how I could make this work?
I have done this with queries before, but I am not sure how to pull N count if use query. Happy to go that route as well if its easiest
use:
=COUNTA(IFNA(QUERY(C:G,
"select C
where 1=1 "&
IF(J2="",," and D = '"&J2&"'")&
IF(J3="",," and F = '"&J3&"'")&
IF(J4="",," and E = '"&J4&"'")&
IF(J5="",," and G = '"&J5&"'")&
" and C <= date '"&TEXT(TODAY(), "yyyy-mm-dd")&"'
and C >= date '"&TEXT(TODAY()-7, "yyyy-mm-dd")&"'", 0)))

Ignore case sensitive for given word

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)&"%'"

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)

QUERY with "contains" and "date range"

I am trying to write a formula that would pull data based on a selection I made and within the date range I put in as well. The code I wrote below does not work. What am I writing incorrectly?!
=QUERY(INDIRECT(CONCATENATE(A2,"!A:FB")), "where (C >=date '"&TEXT('Feedback Report'!C3,"yyyy-mm-dd")&"' and C <= date '"&TEXT('Feedback Report'!D3,"yyyy-mm-dd")&"' and E contains '"&B2&"' ",1)
I asked too soon. After trying one more time, I have found a solution:
=QUERY(INDIRECT(CONCATENATE(A2,"!A:FB")), "Select * where (C >=date '"&TEXT('Feedback Report'!C3,"yyyy-mm-dd")&"' and C <= date '"&TEXT('Feedback Report'!D3,"yyyy-mm-dd")&"' and E contains'"&B2&"')")
Here is the breakdown:
Formula is on a sheet that pulls data from another source (raw data)
INDIRECT(CONCATENATE(A2,"!A:FB")) is where the data is stored
A2 is the sheet I choose from a drop down menu to have the data be pulled from
C is the date column of the raw data
C3 is the starting query date
D3 is the ending query date
E is the category column
B2 is the category value I want to search on
Hope this helps people in the future.

Resources