I have a Google Sheets filter formula that I need to replace with something, I was thinking QUERY, but I can't seem to make that work?
=FILTER(Food!$B:$K,Food!$A:$A=true,TODAY()>=Food!$C:$C,(Food!$D:$D-TODAY())<=14,NOT(ISBLANK(Food!$C:$C)),NOT(ISBLANK((Food!$D:$D-TODAY()))))
I need to IMPORTRANGE the filtered results and they lose their table formatting. I got QUERY working but with fixed dates. I have tried numerous combinations and can't seem to nail down the syntax.
Here is a copy of the sheet and the formula I need help with is in the Specials tab, A2.
https://docs.google.com/spreadsheets/d/16bAAI-A_EMsy1noj8U-fhIuT4XTbfgOJuxvzi_0hYhk/edit?usp=sharing
Thank you!
Does this formula do what you want?
=QUERY(Food!$A:$K,"select *
where A=TRUE
and (C > date '2000-01-01' and C < date '" & TEXT(TODAY(),"yyyy-mm-dd") & "')
and (D > date '2000-01-01' and D <= date '" & TEXT(TODAY()+14,"yyyy-mm-dd") & "') ",0)
The first date test for C and D is to ensure they aren't blank. Using C <> '' or C <> 0 didn't work, I guess since it is a date field.
UPDATE
My mistake - I left out some of the logic I'd included at first.
Try this:
=QUERY(Food!$A:$K,"select B,C,D,E
where A=TRUE
and (C > date '2000-01-01' and C <= date '" & TEXT(TODAY(), "yyyy-mm-dd") & "')
and (D > date '2000-01-01' and (D >= date '" & TEXT(TODAY(), "yyyy-mm-dd") & "'
and D <= date '" & TEXT(TODAY()+14,"yyyy-mm-dd") & "')) ",0)
I got it working by wrapping the FILTER in a QUERY. I had to improve the logic for an End Date >=TODAY() but it worked the way I need after the additional argument.
=QUERY(FILTER(Food!$B:$K,
Food!$A:$A=true,
TODAY()>=Food!$C:$C,
(Food!$D:$D>=TODAY()),
(Food!$D:$D-TODAY())<=14,
NOT(ISBLANK(Food!$C:$C)),
NOT(ISBLANK((Food!$D:$D-TODAY())))))
I'm happy to learn that I can QUERY(FILTER( then IMPORTRANGE the results properly.
Thanks for the interest.
Related
I'm building a sales Dashboard for my company.
I use the following QUERY to list all my employees and their revenue:
=QUERY(Master!A2:O, "
SELECT F, SUM(O), SUM(G)
WHERE A >= date '" & text(D3,"yyyy-MM-dd") & "'
and A <= date '" & text(D5,"yyyy-MM-dd") & "'
AND UPPER(F) contains '"&$L3&"'
AND UPPER(D) contains '"&$L5&"'
GROUP BY F
ORDER BY SUM(G) DESC
LABEL SUM(G) 'Revenue', SUM(O) 'Work Hours', F 'Employee'
")
Some of the data are not attached to a person and their work hours, so I'd like to get rid of these results. To only List my Employees by Work Hours and Revenue.
Here is what I get out of this formula and on the right what I'd like to have:
I would like to cut out the irelevant Online Sales and the Employees who just worked bellow 10 Work Hours.
I tried bellow "GROUP BY F":
AND SUM(O) > 10
HAVING SUM(O) > 10
WHERE SUM(O) > 10
Somehow if I try to filter a SUM() it get's rejacted..
How can I fix that?
try:
=QUERY(QUERY(Master!A2:O,
"select F,sum(O),sum(G)
where A >= date '" &TEXT(D3, "e-m-d")&"'
and A <= date '" &TEXT(D5, "e-m-d")&"'
and upper(F) contains '"&$L3&"'
and upper(D) contains '"&$L5&"'
group by F
order by sum(G) desc
label sum(G)'Revenue',sum(O)'Work Hours',F'Employee'"),
"where Col2 > 10
and not Col1 contains 'Online Sales'", 1)
I have a Google Sheets database that I want to query. I want the query to be based on data in columns B, C, and D and return all data if the conditions are met. I have input cells for the search criteria for those three columns, and I'd like the query to do the following:
Ignore search criteria where there is no value entered in the search cell
Use AND logic where there is a value in a given cell
For example, search criteria in input cells:
B = "1"
C = Blank
D CONTAINS "the"
I want the query to return data where C is anything and B = "1" and D CONTAINS "the".
Another example:
B = "1"
C = "E"
D CONTAINS "the"
I want the query to return data where all three conditions are met
I'd like D to not be null in all cases.
I'm having trouble incorporating the empty criteria into the query. I've tried dynamically using AND/OR depending on whether there's data in a given search cell, but I can't get it to work.
So, I created a crazy-long query to account for all possible combinations with B, C, and D. This works, but I want to incorporate more search criteria, and this equation becomes exponentially more complicated with 4, 5 or more search criteria.
Here is an image of the query input and query results for the first example above (I'm not sure why some of the values in the Name column don't contain "the").
Image of Query Sheet
And here's an image of the database that I'm querying against:
Image of Database Sheet
Here is the equation I'm using:
=if(and(B4="",C4=""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and D IS NOT NULL order by D asc",1),
if(and(B4<>"",C4=""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and B matches '"&B4&"' and D IS NOT NULL",1),
if(and(B4="",C4<>""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and C matches '"&C4&"' and D IS NOT NULL",1),
if(and(B4<>"",C4<>""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and B matches '"&B4&"' and C matches '"&C4&"' and D IS NOT NULL",1),
if(D4="",query(DATABASE!A1:E,"SELECT * WHERE B matches '"&B4&"' "&IF(AND(B4<>"",C4<>""),"AND","OR")&" C matches '"&C4&"' and D IS NOT NULL",
1),FALSE)))))
My ask: I'd like to simplify this equation so that it can be extended to multiple search criteria (more than 3). Thank you for your help!
Try this:
=QUERY(
DATABASE!A:E,
"WHERE D IS NOT NULL"
& IF(B4 = "",, " AND B = " & B4)
& IF(C4 = "",, " AND C = '" & C4 & "'")
& IF(D4 = "",, " AND D CONTAINS '" & D4 & "'")
& " ORDER BY D",
1
)
=QUERY(IMPORTRANGE("xxxxxxx-Sheet-ID"; "Tabelle1!A:D"),
"where C > date'" & text(today(), "yyyy-mm-dd") & "'
and D < date'" & text(today(), "yyyy-mm-dd") & "'", 0)
Can someone told me, why this is not working?
I will get the row informations where the C date is smaller and the D date is bigger than today date.
I the table where i look is this formation 2021-03-29of date
I tried this code above but this is not working... It says ERROR! but i dont see any logs
Assuming you granted permission to pull data from other spreadsheets, try:
=QUERY(IMPORTRANGE("xxxxxxx-Sheet-ID"; "Tabelle1!A:D"); "where C > date '"& text(today(); "yyyy-mm-dd")&"' and D < date '"& text(today(); "yyyy-mm-dd") &"'"; 0)
and see if that works? If not, please share a copy of your spreadsheet (sensitive data erased) so we see how your data is structured.
Note that importrange is only needed if you import data from another spreadsheet. Data imports from within the same spreadsheet can be done without it.
You have to replace C by Col3 and D by Col4 (you can't use A, B, C and D in that case)
=query(IMPORTRANGE("___________","Tabelle1!A:D"), "where Col4 > date '"& text(today(), "yyyy-mm-dd")&"' and Col3 < date '"& text(today(), "yyyy-mm-dd") &"'", 0)
switch Col3 and Col4 as necessary
I am trying to combine two tabs of data to plan a daily routine. One tab is for recurring tasks and one for adhoc tasks.
The data on the tabs are mostly similar except on Sheet1 Col4 is a day of the week, whereas on Sheet2 Col4 is a date
What I would like is to choose the current day of the week and have the query return all recurring tasks for that day, as well as any adhoc tasks for that specific date
I can return both sets of data individually however I can't get the query to return both subsets together
Sheet1 Data
ID,TASK NAME,LOCATION,TASK DAY
REC1,Task 1,Office,Monday
REC2,Task 2,Office,Tuesday
REC3,Task 3,Field,Wednesday
REC4,Task 4,Office,Thursday
REC5,Task 5,Field,Friday
REC6,Task 6,Field,Monday
REC7,Task 7,Field,Tuesday
Sheet2 Data
ID,TASK NAME,LOCATION,TASK DATE
ADH1,AdHoc 1,Office,25/Jun/2019
ADH2,AdHoc 2,Office,26/Jun/2019
ADH3,AdHoc 3,Field,27/Jun/2019
ADH4,AdHoc 4,Office,28/Jun/2019
ADH5,AdHoc 5,Field,29/Jun/2019
ADH6,AdHoc 6,Field,30/Jun/2019
ADH7,AdHoc 7,Field,1/Jul/2019
This pulls the data from sheet 1 based on the day of the week in cell J1
=query({Sheet1!A:D}, "select Col1,Col2,Col3,Col4 where Col4 = """&J1&""" ",0)
This pulls the data from sheet 2 based on today()
=query({Sheet2!A:D}, "select Col1,Col2,Col3,Col4 where Col4 = date '" & text(today(),"yyyy-mm-dd") & "' ",0)
Thought this would work but merely returns an empty set
=query({Sheet2!A:D;Sheet1!A:D}, "select Col1,Col2,Col3,Col4 where Col4 = date '" & text(today(),"yyyy-mm-dd") & "' OR Col4="""&J1&""" and Col1<>'' ",0)
When J1 = Tuesday and date = 25/Jun/2019 I should get
ID,TASK NAME,LOCATION,TASK DAY
ADH1,AdHoc 1,Office,25/Jun/2019
REC2,Task 2,Office,Tuesday
REC7,Task 7,Field,Tuesday
but instead, merely get #N/A
You almost had it.
Rather than put the array inside the queries; put the queries inside the array.
={QUERY(Sheet1!A:D, "SELECT A, B, C, D WHERE D = """&J1&""" ");
QUERY(Sheet2!A2:D, "SELECT A, B, C, D WHERE D = date '" & text(today(),"yyyy-mm-dd") & "'")}
Credit - Stacking multiple query output in one sheet:
Might be too late but issue was in date column after converting it to text query works as well :
=query({Sheet2!A:D; Sheet1!A:D}, "select Col2,Col1,Col3,Col4 where (Col4='"&Sheet1!J1&"' OR Col4 = '" & to_text(today()) & "')",0)
I tried using the following query() in Google Sheets to label my example column R with today's date. However, the query() returns to be invalid.
SELECT A,R LABEL R now()
It has to be a text inside single quotes like 'my custom label':
"SELECT A,R LABEL R '" & text(today(), "MM-DD-YYYY") & "'"