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).
Related
=QUERY(IMPORTRANGE(some_range);"
SELECT Col2,dateDiff(Col20,now())
WHERE Col20 IS NOT NULL AND dateDiff(Col20,now()) <= 30
ORDER BY Col2 ASC
LABEL Col2 'SANITARNA'
";0)
So, i have this query formula which works perfectly for a column that has only dates. However i need to apply it to a column where there are dates and some text values. The problem is when i change the dateDiff column i get an error "Unable to parse query string for Function QUERY parameter 2: Can't perform the function 'dateDiff' on values that are not a Date or a DateTime values" which makes sense. However, i cant seem to figure out how to incorporate a filter within the dateDiff function to just skip the text values and only output the ones that have dates. My best guess so far is that the filter has to be applied within the dateDiff function in SELECT and not WHERE. I've tried a filter/isnumber formula but get parse error and my brain is fried and can't see the problem.
Test sheet: https://docs.google.com/spreadsheets/d/1thpXBSp-Vt1E5MGaM89Xko6GvekjmzyidO94Sil2AjQ/edit?usp=sharing
See my newly added sheet ("Erik Help"), which contains the following version of your original formula:
=QUERY(FILTER(A:C,ISNUMBER(C:C))," SELECT Col1,dateDiff(Col3,now()) WHERE Col2 IS NOT NULL AND dateDiff(Col3,now()) <= 30 ORDER BY Col1 ASC LABEL Col1 'PRIJAVA DO' ",0)
FILTER will first filter in only those rows where the value in Col C is a number. And since all dates are numbers as far as Google Sheets is concerned, that will be only your rows with dates in Col C.
NOTE: You currently have no date values in Col C that are less than or equal to 30 days from TODAY() — that is, all of your Col-C dates are in the future — so your table is returning empty (yet without error, because it is working). Because QUERY is acting on a FILTER of the original data and not on the original data itself, all QUERY column references must be in Colx notation, not A-B-C notation.
The solution Erik Tyler provided works, ill just add here the syntax for the importrange as well for anyone with similar problem.
=QUERY(FILTER(
IMPORTRANGE("some_range";"some_sheets!A:QQ");
ISNUMBER(
IMPORTRANGE("some_range";"some_sheets!C:C")));"
SELECT Col2,dateDiff(Col20,now())
WHERE Col20 IS NOT NULL AND dateDiff(Col20,now()) <= 30
ORDER BY Col2 ASC
LABEL Col2 'SANITARNA'
";0)
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))
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)&"'")
Example
There is range A that stores time and its value and it gets updated dynamically (not in the example).
From that range A, I want to make a dynamic range B of each day and its max value.
Filter() doesn't work with arrayformula and I don't know if query works with it too.
You can do it just with a query:
=ArrayFormula(query({int(A4:A),B4:B},"select Col1,max(Col2) where Col2 is not null group by Col1 label Col1 'Date'"))
as long as you format the date column in the result appropriately.
EDIT
To remove the column labels, just put an empty string as below:
=ArrayFormula(query({int(A4:A),B4:B},"select Col1,max(Col2) where Col2 is not null group by Col1 label Col1 '',max(Col2) ''"))
You can try this (tested on Excel because your Google Sheet is blocked, but it should work perfectly)
=SUMPRODUCT(MAX(--($A$5:$A$31>D5)*--($A$5:$A$31<D5+1)*$B$5:$B$31))
This is how it works:
--($A$5:$A$31>D5) will return an array of 1 and 0 if cell value is higher than date reference. Say date reference is 24/01/2020, then the returned array will be {1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1}
--($A$5:$A$31<D5+1) will do same, but only if cell value is lower to d5+1 (next day). So for 24/01/2020 we would obtain {1;1;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}
First * will multiply both arrays, so {1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1} * {1;1;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0} = {1;1;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}
Second * will multiply previous array by values in range B5:B31, that means {1;1;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0} * {0,333;0,667;0,667;0,667;0,667;0,667;0,667;0,667;0,667;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;0,667} = {0,333;0,667;0,667;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}
MAX will get the max value from previous array (in this case, 0,667)
SUMPRODUCT has been added so we can work with arrays. Normal Max would not do it by itself.
NOTE: Please, notice that my decimal separator is the comma and my argument separator is the semicolon, so probably you will need to fix this acording to your language settings
try:
=SORTN(SORT(FILTER({INT(A5:A), B5:B}, B5:B<>""), 1, 0, 2, 0), 9^9, 2, 1, 1)
I want to set query and importrange formula where i want the new sheet to show date that fall into today and yesterday date only and sort in ascending date and time
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1xk0Cvafixr5dayJkBkrzlYLFoA4E_PHYfPNQis12rc8/edit#gid=1702961582","CONSOLIDATE!A1:H"),"Select Col1,Col2,Col3,Col4,Col5,Col6,Col8 where Col1 <= date '"&text(B1,"yyyy-mm-dd")"' and >= date '"&text(B2,"yyyy-mm-dd")"' and order by Col1,Col2")")"
A couple of syntax errors, should be:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1xk0Cvafixr5dayJkBkrzlYLFoA4E_PHYfPNQis12rc8/edit#gid=1702961582","CONSOLIDATE!A1:H"),"Select Col1,Col2,Col3,Col4,Col5,Col6,Col8 where Col1 <= date '"&text(B1,"yyyy-mm-dd")&"' and Col1>= date '"&text(B2,"yyyy-mm-dd")&"' order by Col1,Col2")
i.e. remember to put '&' after the date as well as before, but don't put 'and' before order by.