How to select a specific cell in Google Sheets' QUERY? - google-sheets

So I have named range called Profil. It is on another sheet. The "C" cell on that query is in Profil range. I want to set C parameter to start date (B3) end date (B4) cell, so the date is dynamically changed according to the start date and end date. Is there any possible way to do it?

I believe this should work:
=QUERY(Profil, "SELECT * WHERE C>=DATE'"&TEXT(B3,"yyyy-mm-dd")&"' AND C<=DATE'"&TEXT(B4,"yyyy-mm-dd")&"'",1)
The query needs the date in a specific format (yyyy-mm-dd), this converts whatever is in cell B3 and B4 into that format and checks the less than / greater than formula.
Works for me:

try like this (with EU locale):
=QUERY(Profil; "where C >= date '"&TEXT(B3; "yyyy-MM-dd")&"'
and C <= date '"&TEXT(B4; "yyyy-MM-dd")&"'"; 1)

Related

Using Index Match with a Sum of a Range

Using Google Sheets:
Here is my current formula that I am using to return the data from ONE Date and I am looking to duplicate this formula except SUM the data of a Date Range.
Current Formula:
=IFERROR(INDEX('Delavan Ford'!$AJ$3:$AJ$1000, MATCH ($B$1,'Delavan Ford'!$V$3:$V$1000,0)),"")
B1= the current single date field that it is looking for a match for and returning the data.
I would be adding another field in B2 to be the second date that it is looking for to return the sum of the data between the 2 dates.
Thanks.
SumIF or SumIFs should work. Personally I prefer to use the QUERY() function as I feel it is more intuitive.
You can use SUMIFS() like-
=SUMIFS(A3:A,V3:V,">="&B1,V3:V,"<="&B2)
Or QUERY() function like-
=QUERY(A3:V,"select sum(A)
where V>= date '" & TEXT(B1,"yyyy-mm-dd") &
"' and V<= date '" & TEXT(B2,"yyyy-mm-dd") &
"' label sum(A) ''")

How do I reference two different variables and a third date range using COUNTIFS

Within a google sheet, on tab 2 I have column A of dates and column B of words. On tab 1, I have a date range in two cells. I am trying to populate the cell if column A falls within the date range of tab 1 and also has the specified word.
Variables to check
Date cells
Using COUNTIFS:
=COUNTIFS(Sheet2!B2:B,"toured",Sheet2!A2:A,">="&A2,Sheet2!A2:A,"<="&A3)
Using QUERY:
=QUERY(Sheet2!A2:B,"SELECT COUNT(A) WHERE B='toured' AND A >= date '"&TEXT(A2,"yyyy-MM-dd")&"' AND A <= date '"&TEXT(A3,"yyyy-MM-dd")&"' label COUNT(A) ''")
Note:
In the spreadsheet you shared, somehow the toured in cell B4 is not getting detected as such, resulting in the returned value being 2. Please rewrite toured in that cell in order to make sure 3 is returned.
Reference:
COUNTIFS
QUERY

Sumifs formula with dynamic date range is not working in google sheet

Here O column is my sum range,
P2 = Date i.e. 2019-05-02
I want to sum all O column range on the bases of the last 30 days. i.e. p2-30.
This formula is working fine in Excel but not working in Google Sheets.
=SUMIFS(O:O,C:C,C2,P:P,"<"&TEXT(P2-30,"yyyy-mm-dd"))
I am really new to this and would appreciate any hints.....
You might want to give the QUERY function a try.
In
F1: =text(today()-30;"yyyy-mm-dd")
H1: =query(O1:P18;"Select sum(O) where P> date '"&F1&"'")
In case you don't want a header
H1: =query(O1:P18;"Select sum(O) where P> date '"&F1&"' label sum(O) ''")
QUERY is a very nice function. Using a date can be a bit tricky, look for examples at https://www.benlcollins.com/spreadsheets/query-dates/
=SUMPRODUCT(QUERY(O1:P, "select O
where P <= date '"&TEXT(C2, "yyyy-MM-dd")&"'
and P >= date '"&TEXT(C2-30, "yyyy-MM-dd")&"'", 0))

Google Sheets: query to convert column to date and compare to another date [duplicate]

This question already has an answer here:
How to compare dates or date against today with query on google sheets?
(1 answer)
Closed 5 months ago.
I need to compare a text column, which contains a string that represents a date in the format dd/mm/yyyy, to another date.
The range is in another sheet. I cannot edit it to format the column to a date field:
I need something like this:
=query(importrange(...); "select A, B WHERE C >= '2017-01-08'")
Of course this doesn't work because only Aldo row will be visible. Is there any way to convert, in the query function, the column C to a date or to a string with the pattern yyyy-mm-dd to compare it to the right hand side value of the comparison?
Cumbersome but seems to work:
Import (say to Sheet1!A1):
=importrange(" k e y ","Sheet1!A:C")
Add a column with recognisable date formats (say in D1):
=ArrayFormula(datevalue(C1:C))
then apply the query:
=query(Sheet1!A:D,"select A,B,C where D >= date '2017-01-08' ")
I know this is WAY late, but I ran into this same problem a couple of years ago and fixed it by doing the following:
Cell A1 contains: 2/21/2018
Cell A2 contains: =DATEVALUE(B1)
which results in 43152 and I copy into the QUERY statement:
Cell A5 formula: =QUERY(Sheet!Range, "select B, C, E where B=43152")
But, to make it somewhat better by only having to type in the date, I used the CONCATENATE function to create the text "select B, C, E where B=43152" in a cell and then referenced that cell in my QUERY, like so:
Cell B1: =CONCATENATE("select B, C, E where B=", A2)
Cell A5 formula: =QUERY(Sheet!Range, B1)
This works well for me and I hope it helps someone else or at least gives someone an idea.

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