Query Selector, Where Clause comparing dates - google-sheets

I am trying to get the selective data from a Sheet.
I am getting Column U in comparision with Column P
Column U = Unique Data
Column P = Date and Time Associated with it.
Column U Column P
564865 2020-06-13 5:52:00
I would like to get the data of the day before current day while truncating time of Column P.
i am trying to use this query, but i am getting some error.
=QUERY('Shopify Unfulfilled'!1:2615,"Select U WHERE "&LEFT('Shopify Unfulfilled'!P:P,10)& "=" &TODAY()-1&"")
ERROR:
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " <ID> "Created "" at line 1, column 16. Was expecting one of: "(" ... "(" ...
Thank you.

See if this works
=QUERY('Shopify Unfulfilled'!1:2615,"Select U WHERE todate (P) = date '"&TEXT(today() -1, "yyyy-MM-dd")&"'", 1)

Related

How to use Query Function in Google Sheets to pull data from a list within a date range?

I have a long list of information that I want to split into month to month sheets. I tried the Filter Function, The Match+Index Function and the Countif function and the error I kept getting said that the formula had more arguments than expected.
Eventually I settled on using Query, and I think I've got the formula roughly right, but I've been trying to troubleshoot this error and I'm completely stuck.
Here is the formula:
=QUERY(Index!1:1988, " SELECT D WHERE (D => date ‘2020,9,1’ and D =< date ‘2020,9,30’)")
And this is the error I keep getting:
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "D "" at line 1, column 18. Was expecting one of: "(" ... "(" ... "(" ... "(" ...
try:
=QUERY(Index!D:D, "where D >= date '2020-09-01' and D <= date '2020-09-30'", 0)

Query one column for matches, then return an array of data in the column directly to the left

I tagged sql in here because apparently the query function uses the same syntax.
My goal is for:
Each data value in column E to individually query column B for matches
If there is a match, add it to a array
Display the array in column G (next to the corresponding cell)
EX:
If I query column B for "Heavy lifting/straining", the cell in column G will show "Musculoskeletal, Herniation"
try this:
=JOIN(", "; FILTER(A:A; B:B=E7))
for partial matches:
=JOIN(", ", FILTER(A:A, REGEXMATCH(B:B, E8)))

Query formula Google Sheets with time

Does anyone know how I can add to the below query to find results between 2 time periods and sort from earliest to oldest.
'"&B5&"' in the query = MONDAY.
P in TempCSV is time from splitting date & time in column D with this formula in column O =iferror(split(D2, " ")) and this continues down the column for all other rows.
I cant use date and time from D as the date is creation date and not current date in relation to what I'm trying to achieve.
=query(TempCSV,"Select A,D where A contains 'Something' and A contains 'Anotherthing' and C contains '"&B5&"' **where P >=05:00:00 and P <=12:00:00**")
I have successfully got the following to work in another range but this is due to the date and time being correctly recorded in the same cell.
=query(TPM,"SELECT A,B,C where A contains 'Something' and A contains 'Anotherthing' and C >= datetime '"&text($C$5,"yyyy-mm-dd 05:00:00")&"' and C < datetime '"&text($C$5,"yyyy-mm-dd 12:00:00") & "'")

Get all the timestamp values from a range, within the past 24 hours

I have a Google Forms data where I only want to perform the past 24 hours of inputs. The formula I am using is:
=ARRAYFORMULA(QUERY('Production Log'!A:A,"Select A where hour(timevalue(now())-timevalue(toDate(A))) <=24"))
But I am getting this error:
Error
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "hour" "hour "" at line 1, column 16. Was expecting one of: "(" ... "(" ...
Filter may be simpler:
=filter('Production Log'!A:A,(now() - ('Production Log'!A:A)) < 1)
try:
=QUERY('Production Log'!A:A,
"select A
where A = date '"&TEXT(TODAY()-1, "yyyy-mm-dd")&"'", 0)

Using Google Spreadsheets QUERY to Filter

I have the following google sheet where:
Col a= quantities
Col b= product codes, which i´ve split between C and H.
I want to know the quantity according to different "filters"... this filters are the fields between C11 and H11, and they are optional. There are 6 possible filters.
It works using =QUERY formula located in H12 and it returns the sum of quantity values where the filters match...
BUT there´s the possibility of leaving a filter empty to get "all"...
the query is as follows:
=QUERY(A1:H7, "select sum(A) where C contains '"&C11&"' and lower(D) contains lower('"&D11&"') and E contains '"&E11&"' and lower(F) contains lower('"&F11&"') and lower(G) contains lower('"&G11&"') and lower(H) contains lower('"&H11&"') ",-1)
My problem is with the match type: where C contains '"&C11&"' and...
instead of using "contains" it should compare using "matches". this way it would count like it should, but then it won´t accept empty filters.
How can I get it to count only if the field is filled??
What´s wrong with the filter right now? It´s counting "4" matches because model matches "1" happens when model is 1 or 21, also with column D where i´m looking for value X and is also counting value XN as it contains "X". if formula is changed to "matches" instead of "contains", it won´t allow me to leave it blank.
Thank you!
Karl_S formula is great, but it does not sum the quantities in column A. Adapting his approach to SUMIFS seems to do it:
=SUMIFS(A2:A7,C2:C7, IF(ISBLANK(C11), "<>" ,C11),D2:D7, IF(ISBLANK(D11), "<>" ,D11),E2:E7, IF(ISBLANK(E11), "<>" ,E11),F2:F7, IF(ISBLANK(F11), "<>" ,F11),G2:G7, IF(ISBLANK(G11), "<>" ,G11),H2:H7, IF(ISBLANK(H11), "<>" ,H11))
Use this formula instead:
=COUNTIFS(C2:C7, IF(ISBLANK(C11), "<>" ,C11), D2:D7, IF(ISBLANK(D11), "*",D11), E2:E7, IF(ISBLANK(E11), "<>",E11), F2:F7, IF(ISBLANK(F11), "*",F11), G2:G7, IF(ISBLANK(G11), "*",G11), H2:H7, IF(ISBLANK(H11), "*",H11))
If one of the options is blank, it will match all items in that column. Otherwise it should do an exact match.

Resources