Context
Following on from this question, I am trying to make this more dynamic. I want to input data in a cell 'D1' to then make Query bring back the data from another spreadsheet. Below is a depiction of what this looks like.
This is the formula I tried:
=QUERY(Query(ImportRange("ID", "AvevaGroupPrice"),"offset 1", 0), "where Col1 >= Date " &D1)
I used this format because eventually I want to create a dynamic date range where I type the respective dates I need in the first two 'D' rows.
Problem
How can I make this work using data in cell D1?
Based on the Query Language Documentation, when you include date keyword you need to use a date with yyyy-mm-dd format
In your current function, the date was converted to a number when appended to the string.
Sample: ="date "&D1
Result: date 43830
You need to use TEXT() to convert the date to yyyy-mm-dd format.
Sample: ="where Col1 >= Date '"&TEXT(D1,"yyyy-mm-dd")&"'"
Result: where Col1 >= Date '2019-12-31'
(UPDATE)
You can also use TO_TEXT() to convert the Cell Value to a text value.
Sample: ="where Col1 >= Date '"&To_text(D1)&"'"
Result: where Col1 >= Date '2019-12-31'
Your Formula:
=QUERY(Query(ImportRange("ID", "AvevaGroupPrice"),"offset 1", 0), "where Col1 >= Date '"&TEXT(D1,"yyyy-mm-dd")&"'")
or
=QUERY(Query(ImportRange("ID", "AvevaGroupPrice"),"offset 1", 0), "where Col1 >= Date '"&To_text(D1)&"'")
Related
I want to write a query to combine data from two sheets with same heading where data in first column is either a date or a specific string.
Example
=query({Sheet1!A:B;, Sheet2!A2:B}, "select * where Col1 > date 'YYYY-MM-DD' OR Col1 = 'example string' ")
The values are reflecting for date but not for the example string.
The example string entered for Col1 in the formula, is selected from a pulldown list in sheet2.
better try:
=FILTER({Sheet1!A:B; Sheet2!A2:B},
({Sheet1!A:A; Sheet2!A2:A}>"01/01/2000")+({Sheet1!A:A; Sheet2!A2:A}="example text"))
I have an importrange array to get data from alot of sheets. I organise zhem into one list and then make calculations from this list.
WORKBOOK
https://docs.google.com/spreadsheets/d/1OH_LF9r04rRb1ZMuc26CwIq3NQ-qWVlb8mXJwuTechk/edit#gid=28668687
SOURCE WORKBOOK (Tracker)
https://docs.google.com/spreadsheets/d/1huVGusrmhZ60zy9pg59PKN_yfL1XulwvLW5EWwHguvA/edit#gid=2007038591
sheet MODTANEWBIE_QUERY
formula #1 (add UID to DATE):
=IF($B$2="No","",ARRAYFORMULA({MODTANEWBIE_PER!A$3&"#"&QUERY(IMPORTRANGE(MODTANEWBIE_PER!$C$3,"Tracker!"&B$3&":"&B$4&MODTANEWBIE_PER!$D$3),"select Col1 WHERE Col1 = "&A2)}))
formula #2 (get data from specific column in #Tracker based on date)
=IF($B$2="No","",ARRAYFORMULA({QUERY(IMPORTRANGE(MODTANEWBIE_PER!$C$3,"Tracker!"&B$3&":"&B$4&MODTANEWBIE_PER!$D$3),"select Col1 WHERE Col1 = "&A2)}))
For some reason I an unable to query the importrange's Date that corresponds to the cell A2 in _QUERY sheet.
Please am I missing something silly? Is there a format problem?
Thanks alot for any help!
formula should be:
=IF($B$2="No",,ARRAYFORMULA(MODTANEWBIE_PER!A$3&"#"&QUERY(IMPORTRANGE(MODTANEWBIE_PER!$C$3,"Tracker!"&B$3&":"&B$4&MODTANEWBIE_PER!$D$3),"select Col1 WHERE Col2 = date '"&TEXT(A2, "e-m-d")&"'")))
however:
tracker sheet does not contain today's date so A2 needs to be a valid date
dates on tracker sheet are in column B so B4 cant be A
query will then look for where Col2 where dates are
and query is picky on dates if they are not in this format: yyyy-mm-dd
I have a sheet with a Name Column and corresponding Date column. I'm attempting to count the number of times unique Names appear for a specific Date range. The data is in a separate spreadsheet, so I'm using importrange in the formulas.
I created a sample spreadsheet here - we can pretend that the "Data" tab is on a separate spreadsheet file. I have the below formula so far but I'm not sure how to tell it to only count the unique Name values between the Dates in cells B2 and C2.
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1VHR-T9bo0E1KH4yZp-9wTW6JGjKh4b3qMdm99MP_vB8/edit#gid=0","Data!A:B"),"Select Count(Col1) where Col2 >= date '"&TEXT(B2,"yyyy-mm-dd")&"' and Col2 <= date '"&TEXT(C2,"yyyy-mm-dd")&"' Label Count(Col1) ''")
Thanks for your help!
This formula should do it:
=COUNTUNIQUE(QUERY(IMPORTRANGE("1VHR-T9bo0E1KH4yZp-9wTW6JGjKh4b3qMdm99MP_vB8","Data!A2:B"),"select Col1 where Col2 >= date '"&TEXT(B2,"yyyy-mm-dd")&"' and Col2<= date '"&TEXT(C2,"yyyy-mm-dd")&"'",0))
I am trying to use the filter function to show only data in combination with the importrange function that meets certain conditions. I currently have the following formula:
=filter(ImportRange("XXXXXXX","Sheet1!A2:A"),ISBLANK(ImportRange("XXXXXXX","Sheet1!C2:C")),CONDITION2?)
So I currently have 1 condition that works, import the range if the value in range(C2:C) is blank; however, I am having trouble figuring out adding the second condition where it will import the range if there is a date and if that date is >= Today() in range(C2:C).
It is preferable to you use Query instead:
=QUERY(ImportRange("XXXXXXX","Sheet1!A2:C"),"Select Col1 where Col1 is not NULL and Col3 is NULL or Col3 > now()")
In order for this solution to work, column C must contain the dates in the correct format or null values (empty cells).
I am using query and importrange function to collect data from another Google sheet, I am filtering by the Publisher and the user-specified Start Date (F1) and End Date (G1). What I have right now works just for the start date, except that I haven't been able to filter it between the two dates. So I would like to keep all of the data that has fallen within the start date or the end date. Start date is Col9 and End Date is Col10 in the source data
The next step for this would be to change the start date and end date if it is less than or greater than the user-specified dates. For example, if the start date based on the importrange function is July 15th, but the user-specified date is August 1st then I want the cell with that date to be August 1st. The same logic applies to the end date, except any end date greater than the user-specified date should be changed to August 31st in this case. Is including this aspect in a single formula possible? Or would I have to create a separate query/script?
Below is a link to a copy of the formula I'm working with:
https://docs.google.com/spreadsheets/d/1hdE2q8UDdStx98WH9de3PljiMZzasZzhBChUAxLPgGQ/edit#gid=28163102
Below is the source data:
https://docs.google.com/spreadsheets/d/1N8m_YtO1Nc5AXSCAvT5Z1RiKs30bwjt6XDk9zA5QSOE/edit?usp=sharing
If I remove " and Col10 <= date '"&text(G1,"yyy-mm-dd")&"' " from the code, it works with the start date.
=QUERY(importrange("https://docs.google.com/spreadsheets/d/1N8m_YtO1Nc5AXSCAvT5Z1RiKs30bwjt6XDk9zA5QSOE/edit#gid=0","Activity Tracker - Publisher Co!B10:K"),"Select Col6, Col1, Col2, Col4, Col9, Col10 where Col2 is not null and Col9 is not null and Col1 contains 'Publisher 1' and (Col9 >= date '"&text(F1,"yyy-mm-dd")&"' and Col10 <= date '"&text(G1,"yyy-mm-dd")&"')")
try:
=QUERY(IMPORTRANGE(
"1N8m_YtO1Nc5AXSCAvT5Z1RiKs30bwjt6XDk9zA5QSOE",
"Activity Tracker - Publisher Co!B10:K"),
"select Col6,Col1,Col2,Col4,Col9,Col10
where Col2 is not null
and Col9 is not null
and Col1 contains 'Publisher 1'
and Col9 <= date '"&TEXT(G1, "yyyy-mm-dd")&"'
and Col10 >= date '"&TEXT(F1, "yyyy-mm-dd")&"'", 0)