Pass a Date value from a cell in Google Sheet formula - google-sheets

How do I re write this query for Google sheet, so that the dates in column B can be taken from a cell say X1 and X2
=QUERY(master!A:N,"select B,D,H where B>=date '2021-10-01' and B<=date '2021-10-31' and (E='3-MonoYarnSupply' or E='4-MultiYarnSupply') label B 'Date',D 'Particulars',H 'Quantity Supplied'")
Expected formula
=QUERY(master!A:N,"select B,D,H where B>X1 and B<=X2 and (E='3-MonoYarnSupply' or E='4-MultiYarnSupply') label B 'Date',D 'Particulars',H 'Quantity Supplied'")
Where X1 = 01-10-2021 and X2 = 31-10-2021

You can split the formula and use string concatenation logic to refer to other cells like this:
=QUERY(A:N,"select B,D,H where B>=date '" & TEXT(X1, "YYY-MM-DD") & "' and B<=date '" & TEXT(X2, "YYY-MM-DD") & "' and (E='3-MonoYarnSupply' or E='4-MultiYarnSupply') label B 'Date',D 'Particulars',H 'Quantity Supplied'")

B >= date '"&TEXT(X1,"yyyy-mm-dd")&"' and B <= date '"&TEXT(X3,"yyyy-mm-dd")&"'
Thank you #Gangula. Qualifying the date values as above in the query helped to achieve what I required. Thank you for your time.

Related

Google sheet text formula not working; query by date and text() not working

[![enter image description here][1]][1]
So I am trying to pull a query by date, but when I do exactly like the tutorials I found on the internet it just doesn't work,
i.e. :
=QUERY(Penjualan!$A$1:$H$136,"select A , B , D , H where B > date '"&TEXT(TODAY(),"yyyy-mm-dd")&"'",1)
or
=QUERY(Penjualan!A1:H; "select A , B , D , H where B = date '"&text(D1, "yyyy-mm-dd")&"'" )
does anyone know what is wrong?
try like this:
=TEXT(TODAY(); "yyyy-mm-dd")
=QUERY(Penjualan!A1:H;
"select A,B,D,H where B = date '"&TEXT(D1; "yyyy-mm-dd")&"'")
=QUERY(Penjualan!A1:H;
"select A,B,D,H where B > date '"&TEXT(TODAY(); "yyyy-mm-dd")&"'"; 1)

Google Sheets Two Lists as Criteria for Query

I have the following query which is working fine. However I'd like to adde some additional logic if possible where if the there is a value in K3 then ideally the query would not use WHERE R = '"&$K2&"' in the query below but rather use WHERE D = '"&$K3&"'.
Here is a sample sheet. https://docs.google.com/spreadsheets/d/1Lt0RzwtuqIrxWYmWnYK4nh0JN2WdM0icpYF9oXGRfB8/edit?usp=sharing
QUERY(Transactions,"SELECT C,D,B,E WHERE R = '"&$K2&"' AND B > date '"&TEXT($C$2,"yyyy-mm-dd")&"' AND B <= date '"&TEXT($C$3,"yyyy-mm-dd")&"'
",1)
Try
=QUERY(Transactions,"SELECT C,D,B,E WHERE "&if(K3="",L2,L3)&" = '"&if(K3="",K2,K3)&"' AND B > date '"&TEXT($C$2,"yyyy-mm-dd")&"' AND B <= date '"&TEXT($C$3,"yyyy-mm-dd")&"' ",1)
with R and D in L2/L3

Google Sheet: Using drop-down and check-boxes (data type: text & True/False) to filter data

firstly thanks in advance.
Before posting this, I’ve searched and tried a few guides from several sources. However, was to no success in constructing formula string. Filtering data in Google sheet (GS) using Query + other functions is something new to me and I’m still learning.
Goal:
Use drop-down and 2 types of check-boxes (data type: text & True/False). User can select one or more checkboxes to filter data.
Problem:
Was not successful to construct formula string to combine drop-down & check-boxes
My GS example was taken from one of the solution which used a simple formula string for check-boxes (data type: True/False) to create filter and hoping I could developed from it.
My Google sheet link
Thanks again!
This seems to do what you've asked for. Try the following formula in E6 of your results sheet. Or see my tab Answer-GK, which I added to your sheet.
=iferror(if(or(C5:C13),
QUERY ('Test string DB'!A3:H12, "Select * WHERE " &
IF(B2="","C <>'' "," C = '"&B2&"'") &
IF(C5, " and D matches '" & B5 & "' ",) &
IF(C6, " and D matches '" & B6 & "' ",) &
IF(C7, " and D matches '" & B7 & "' ",) &
IF(C8, " and E matches '" & B8 & "' ",) &
IF(C9, " and E matches '" & B9 & "' ",) &
IF(C10, " and E matches '" & B10 & "' ",) &
IF(C11, " and F=TRUE", ) &
IF(C12, " and G=TRUE", ) &
IF(C13, " and H=TRUE", )),
QUERY ('Test string DB'!A3:H12,"select * " & if(B2=""," "," where C = '"&B2&"'") ,0)),
"No results - Reduce your selected criteria")
Something to note. Since some of your data elementss have dedicated columns, and others are shared columns, it limits what you can filter. For example, you can't find a campsite that has a beach AND a lake, since your data only allows you to have one or the other element.
The same for access - it can't be both walking and 4WD. So if you check two or more tickboxes, for either Features or Accessible By, you get no results. You don't have this issue with Ammenities, since you have a separate column (data element) for each of shower, toilet, and plugpoint. I hope this makes sense, I assume that you may want to expand your data structure to allow multiple elements, as you have for Amenities. The formula would need to be modified in that case.
But otherwise I think it is working as you intended.
Let us know of any issues with this.
UPDATE:
To perhaps improve the appearance, I modified The "TRUE" values to show as "Y", using hidden columns in J to L, and the following formula in M5. There are also other ways of doing this.
={"Toilet","Shower","Plugpoint";
arrayformula(if(J6:L,"Y",""))}
This adds the three header labels, then looks through columns J,K,L for TRUE values, and returns them as "Y"s.
I am assuming you intended the the Feature and Accessible check boxes to be inclusive and the Amenities to be exclusive. Here is a working example:
https://docs.google.com/spreadsheets/d/1AqQCKRrhTzJyLWldcpeFAv1o4sLvphv3F52VCgpa4rE/edit?usp=sharing
Here is the formula in E6:
=iferror(QUERY(QUERY('Teststring DB'!A3:H12,"select * where C = """&B2&""" AND (D = """& if(C5 = true,B5,"")&""" OR D = """& if(C6 = true,B6,"")&""" OR D = """& if(C7 = true,B7,"")&""") OR (E = """& if(C8 = true,B8,"")&""" OR E = """& if(C9 = true,B9,"")&""" OR E = """& if(C10 = true,B10,"")&""") ",0),"select * " & if(C11 = true,"where Col6 = true","")&" " & if(C12 = true,if(C11 = true,"AND Col7 = true","where Col7 = true"),"")&" " & if(C13 = true,if(or(C11 = true,C12 = true),"AND Col8 = true","where Col8 = true"),"")&" ",0),QUERY('Teststring DB'!A3:H12))

Referencing a cell in query function not included in range in google sheets

I'm trying to write a query function that selects a value from a column on a different sheet where a different column from the same sheet is equal to a cell on the target sheet.
Here's my attempt at trying to show this with code:
=QUERY(OtherSheet!D:E,"Select E where (D = D8)")
D8 is the cell from the target sheet that I want to reference.
should be:
=QUERY(OtherSheet!D:E, "select E where D = "&D8)
if D8 is a numeric value
otherwise, if D8 is plain text it should be:
=QUERY(OtherSheet!D:E, "select E where D = '"&D8&"'")

Creating a query that will filter based on multiple criteria from dropdown menus in Google Sheets

I am trying to create a dashboard that will filter data based on multiple criteria.
Here is a copy of the spreadsheet: https://docs.google.com/spreadsheets/d/1sJcsu0VpnLBi7wh4l-NEFdYfkxWgC6vpX8AeN9u-KlQ/edit?usp=sharing
I am having a hard time getting the query to work as I want.
I have created data validation cells for several search criteria (Name, reporter, incident type, location, start date, end date).
There are four columns for student names, based on the way the form is set up. I am able to get it to filter based on the student name using this formula: =QUERY('Form Data'!$A$2:M,"Select * where B = '"&E1&"' OR C = '"&E1&"' OR D = '"&E1&"' OR E = '"&E1&"'",0)
When I try to add other criteria, the formula breaks down. I've tried:
Select * where B = '"&E1&"' OR C = '"&E1&"' OR D = '"&E1&"' OR E = '"&E1&"' AND D >= Date '"&B11&"' AND A <= Date '"&B12&"' to try and filter date, but I'm getting an error. It says the date format isn't correct, but it's formatted yyyy/MM/dd as it says it should be.
I also tried: =QUERY('Form Data'!$A$2:M,"Select * where B = '"&E1&"' OR C = '"&E1&"' OR D = '"&E1&"' OR E = '"&E1&"'" &if(B5="All",,"'"&B5&"'"),0); this works when "All" is selected, but not when I pick another name from the drop down list.
Any help would be enormously appreciated
try:
=QUERY('Form Data'!A2:M,
"where (B = '"&E1&"'
or C = '"&E1&"'
or D = '"&E1&"'
or E = '"&E1&"')
and A >= date '"&TEXT(B11, "yyyy-mm-dd")&"'
and A <= date '"&TEXT(B12, "yyyy-mm-dd")&"'", 0)

Resources