Google Sheets Query by Date and Group missing data - google-sheets

I am trying to query a data set by date and return ID's that are not listed in the queried date range as compared to a master list. I have set up this Google Sheet as an example.
I know and understand how to use the query function to select data by the dates:
=query(Datasheet!$A$2:$B,"Select B where A > date '"&TEXT('Querysheet'!$A$3,"yyyy-mm-dd")&"' and A <= date '"&TEXT('Querysheet'!$B$3,"yyyy-mm-dd")&"' ...")
The part that I am missing is how to compare and return a group of ID's that are missing from the Datasheet compared with the Mastersheet.

use:
=UNIQUE(FILTER(Mastersheet!A2:A, NOT(COUNTIF(UNIQUE(QUERY(Datasheet!A2:B,
"select B
where A > date '"&TEXT(Querysheet!A3, "yyyy-mm-dd")&"'
and A <= date '"&TEXT(Querysheet!B3, "yyyy-mm-dd")&"'")), Mastersheet!A2:A))))

Related

In Google sheets, can a QUERY statement determine the oldest date in a column, add 6 months to it , then display that range?

Currently, I am having to query the entire set, jot down the oldest date, and then add a GTE (>=) and a LTE (<=) back into the query statement to limit the results to 6 months, like this:
=QUERY(RawData!A1:D, "SELECT * WHERE A = 'N502SY' and C >= date '2020-03-20' and C <= date '2020-09-20' ORDER BY C ASC")
Ideally, the query statement would determine ON ITS OWN what the oldest date is and then display all rows found with that date PLUS all rows that have a date within a 6-month period (from the oldest date).
Have done a ton of google searching to find an answer but have come to the conclusion that QUERY statements may not be as robust as I am hoping for. Here is the URL (kindly do not change the raw date):
https://docs.google.com/spreadsheets/d/17n3PYBrhlbD1RIgToohS3a1QbN5qhrQnREcMAnZdcbY/edit#gid=626607315
your shared sheet has restricted access. so here's a working formula based on rough sample data.
=QUERY(A:D, "SELECT * WHERE A = 'N502SY' and C >= date '"&text(EDATE(MAX(C:C),-6),"yyyy-mm-dd")&"' and C <= date '"&text(MAX(C:C),"yyyy-mm-dd")&"' ORDER BY C ASC")
-
You can try with FILTER and SORT too:
=SORT(FILTER(A1:D,A:A="N502SY",C:C>=EDATE(MAX(C:C),-6)),3,1)

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.

How to query Google spreadsheet cell for date before 2016-02-16

I have a Google spreadsheet containing subscriptions. I need to query that spreadsheet to find out what subscriptions have expired. By searching on the internet, I've found I can query the spreadsheet to find out which subscribers expire after a certain date (2016-02-16 in this example) with this command:
=QUERY(Everyone!$A:$ZZ, "SELECT * WHERE H >= date '2016-02-16' ORDER BY H",-1)
(The expiration date is in column H.)
If the date in question is in a certain cell (E2 in this example) I can do that here too:
=QUERY(Everyone!$A:$ZZ, "SELECT * WHERE H >= date '" & text(E2,"yyyy-MM-dd") & "' ORDER BY H",-1)
I want to know the subscribers that have an expiration date before 2016-02-16. I thought I could just replace the >= with <, but that returns no results. (I know I have dates before 2016.)
So my question:
How to query in a Google spreadsheet to find all dates less than a specified date?
If you look at the bottom of your sheet you will see your data. The issue is with Order By. The null cells in H are sorted first. Add AND H IS NOT NULL and it should solve this.
=QUERY(Everyone!A:J, "SELECT * WHERE H < date '2016-02-16' AND H IS NOT NULL ORDER BY H",-1)
Another option would be to have the exact row numbers Everyone!A1:J16. Then blank cells are not an issue.
Why not just make use of a filter? You can do that such as
=filter(Everyone!$A:$ZZ, H4:H>H3)
//Where H3 is where you put the date of your choice.

matching a date in a google spreadsheet

I am trying to match a date within a google spreadsheet, but I am new to this, and I could use some help. I have a column that contains a list of birthdays. I have a cell that I am using to reference for the current date by using
=Today()
What I would like to do is compare the month and day, but ignore the year, and return the values in the two adjacent columns. I am using this query to try to get the information.
=QUERY(C2:E430; "select * where C = date '" & text(F2,"yyyy-MM-dd") & "'")
but it always returns an empty output, because the year never matches. How do I get it to ignore the year?
Thank you,
Paul
One way would be to compare the month and day separately (note that the MONTH() spreadsheet function is January = 1, while the month() function in the QUERY select clause is January = 0).
=QUERY(C2:E430;"select * where month(C) = "&(MONTH(F2)-1)&" and day(C) = "&DAY(F2))

Google Sheets QUERY...WHERE stopped working

I use the Google Sheets SQL-ish Query function to summarize data in a number of my spreadsheets. This has been working well for years, albeit slowly.
Today, I'm having problems with some of my queries - specifically with some that compare dates in the source data to TODAY().
To demonstrate, here's a link to a shared spreadsheet that I've used to reproduce the problem on fake data.
Edit: Example has been updated with AdamL's suggestion.
The source data is in range A1:D6, with columns "Serial No.", "Type", "Location", and "Warranty Expiration". The last column is a date.
This function in A9 summarizes all data:
=query(A1:D6,"select B, count(A) group by B pivot C")
...like so:
Here's the thing. If I try to filter using WHERE and DATE(), the Query seems to break down completely. What I want is a table that looks like the one above, but including only data rows that have a date in column D that is in the past.
=query(A1:D6,"select B, count(A) where D < now() group by B pivot C")
If I change the filter to something not involving dates, I get the expected output:
How do I get this to give me the summary I want?
The now() scalar function returns a datetime value, and you have date values in the source data. Comparisons between the two will unfortunately fail. The workaround is to convert now() to a date value:
=QUERY(A1:D6;"select B, count(A) where D < toDate(now()) group by B pivot C")
As an aside, there is a limitation (bug?) with the QUERY function whereby the now() scalar function does not (necessarily) operate in the time zone of your spreadsheet, and there doesn't appear to be any way of modifying this behaviour. I believe that the now() scalar function will always return the current time in Pacific Daylight Time (eg US west coast). So for me, right now in Brisbane, Australia, toDate(now()) used in a QUERY select clause returns yesterday's date.
The safer bet is to use a spreadsheet function to generate today's date, and concatenate that into the QUERY clause:
=QUERY(A1:D6;"select B, count(A) where D < date '"&TEXT(GoogleClock();"yyyy-MM-dd")&"' group by B pivot C")

Resources