Query function with manipulation of dates

This post is in continuation of my earlier post on query function. for basic understand the query function have a look at the following link https://anandexcels.wordpress.com/2013/11/01/query-function-in-google-sheets/

https://anandexcels.wordpress.com/2013/11/07/single-column-manipulation-using-query-function/

https://anandexcels.wordpress.com/2013/11/08/query-function-refering-to-cell-value/

Now we will see how to manipulate Query function with DATES, manipulation of date is query function is tricky. some query does not understand the date because in the spreadsheets dates are treated as serial numbers and query understanding it as text. We have to trick the query function

(Q) Suppose we want list the data based on the certain dates referring to cell

we will continue to use the old example in my first query post

solution is as follows:

=QUERY(A:D;”select * where D>=date”””&text(F1,”yyyy-mm-dd”)&””” and D<=date”””&text(G1,”yyyy-mm-dd”)&””””)

 

where F1 is the start date and G1 is the end date

Observations

(1) There are three double quote before text function and after text function

(2) we have used the text function to convert the numbers into text

(3) date has to be formatted in yyyy-mm-dd format only.

the link to spreadsheet is available in my first blogpost listed above

 

Advertisements

Query function refering to cell value

This post is in continuation of my earlier post on query function. for basic understand the query function have a look at the following link https://anandexcels.wordpress.com/2013/11/01/query-function-in-google-sheets/

Now we look at the referring to cell value within query function so that query function will be more robust.

(Q) What is sales value during the period for Britney

we will continue use our old data set

(A) The formula we are using is

=QUERY(A:D;”select B, Sum(C) where B ='”&F1&”‘ group by B label Sum(C) ‘Sales'”;1)

the results will be

where cell F1 contains the criteria in our example Britney

now we do not need to change the formula, if you change the cell value of F1 to from Britney to Paris the query function recalculates the values

the results will be

 

Observations:

(1) Remember query function is case sensitive

(2) if you use paris instead of Paris you may get the null string without any error

(3) observe the syntax after where B =

(4) if Cell F1 is string you have use single-quote double-quote ampersand then F1 similarly after F1 also, this is a syntax you have to follow