I have seen the use of a reference cell to take the query place of the function.
For example:
Instead of A4 containing the entire function:
=QUERY('Staff List'!A2:E12, "SELECT A, B, C, E WHERE E = 'No'")
The query is referenced in another cell like this.
=QUERY('Staff List'!A2:E12,A1)
where A1 contains "SELECT A, B, C, E WHERE E = 'No'"
so instead of Editing A4 you can just edit A1 when needing to change the query.
My Question is this:
Can the same concept be applied to the date I wish to reference in a query?
For example can use something like this
=SORT(Query(A1,"Select * where Col7 >= DATE """&TEXT(A2,"yyyy-MM-dd")&""" AND Col7 <= DATE """&TEXT(B2,"yyyy-MM-dd")&""""),1,true)
where I insert {'1'!P5:V1000;'2'!P5:V1000;'3'!P5:V1000}
into cell A1
Instead of this:
=SORT(Query({'1'!P5:V1000;'2'!P5:V1000;'3'!P5:V1000},"Select * where Col7 >= DATE """&TEXT(A2,"yyyy-MM-dd")&""" AND Col7 <= DATE """&TEXT(B2,"yyyy-MM-dd")&""""),1,true)
So far i had tried this to no avail
=SORT(Query(""A1"","Select * where Col7 >= DATE """&TEXT(A2,"yyyy-MM-dd")&""" AND Col7 <= DATE """&TEXT(B2,"yyyy-MM-dd")&""""),1,true)
=QUERY(1st param, 2nd param, 3rd param)
1st param of query can be referenced only as non-arrayed range like:
=QUERY(INDIRECT(A1))
____
where A1 contains range A1:C
arrayed ranges like these are not allowed:
{A1:C; D1:F}
____
{INDIRECT(A1:C); INDIRECT(D1:F)}
as for the 2nd and 3rd QUERY param, those are allowed to be referenced as a string even if it contains a date atribute
Related
I have the yellow table shown below, and I'm trying to get the blue table, which aggregates columns B:F by value, and then counts the number of 'x' symbols for each row value of column A.
Is there some basic SQL/array magic formula to get this, please? There must be.
Use this new functions formula
=BYROW(B2:4, LAMBDA(v, COUNTIF(v, "=x")))
Used:
BYROW, LAMBDA, COUNTIF
v is the array_or_range
Update
={ A2:A4, BYROW(B2:4, LAMBDA(vv, COUNTIF(vv, "=x")))}
For fun
Update 02
=ArrayFormula(TRANSPOSE(QUERY({
QUERY(TRANSPOSE(IF(A1:4<>"x",A1:4,1)),
" Select * Where Col1 is not null ", 1)},
" Select (Col1),sum(Col2),sum(Col3),sum(Col4) Group by Col1 ", 1)))
For this sample table:
A
B
C
D
E
1
Range!A1:C5
URL1
= Formula here
2
URL2
3
URL3
4
...
I have this working formula in C1:
={IMPORTRANGE(B1, A1); IMPORTRANGE(B2, A1); IMPORTRANGE(B3, A1)}
A1 contains the range to pull from the target Sheets.
Links to the target Sheets are found in column B.
(This is a simplified example. My actual Sheet has 21 entries in column B.)
Question:
If I will have to add/remove URLs in column B, I have to adjust the formula in C1 and add/remove IMPORTRANGEs.
I would like to have a formula that automatically adjusts to the entries in column B.
Solutions tried:
I tried this, but it did not work:
={JOIN("", ARRAYFORMULA(IF(LEN(B1:B), "IMPORTRANGE(""" & B1:B & """, """ & A1 & """); ", "")))}
The JOIN function returns a text that should be identical to what the array { ... } parses as a formula. But it doesn't. Wrapping it with INDIRECT also does not work.
Any suggestions on how I could make this work?
if by "working formula" you mean valid formula that returns data then only thing you can do is hardcode it like this:
=QUERY({
IFERROR(IMPORTRANGE(B1, A1), {"","",""});
IFERROR(IMPORTRANGE(B2, A1), {"","",""});
IFERROR(IMPORTRANGE(B3, A1), {"","",""})},
"where Col1 is not null", )
A1:C5 = 3 columns = {"","",""}
you can generate formula dynamically with arrayformula but the result will be always a text string and not active formula. tho if you wanna go this way you will need a script that will convert your text string into active formula. example:
https://stackoverflow.com/a/73119313/5632629
https://stackoverflow.com/a/61819704/5632629
Good morning!
I want to ask if it is possible that the cell reference for "houses" on "worksheet!C3" return values for A&B only or A&C only or B&C only while only using one cell ("worksheet!C3") as cell reference, or is there a better approach on trying to return the values?
formula I'm using:
sum(query(Encoding!$A$4:$K$9,"Select D where (A contains '"&C$2&"') and (B contains '"&C$3&"') and (C = date '"&text($B$4,"yyyy-mm-dd")&"')"))
Sample data is attached,
https://docs.google.com/spreadsheets/d/1sY6YQRQ6Im-zTdzf0u31rphnQR0eL_YzDahpgMQ7E1Y/edit#gid=37782805
Try, as far as I understood the subject correctly
=sum(query(Encoding!$A$4:$K$9,"Select D where (A contains '"&C$2&"') and (B contains '"&C$3&"' or B contains '"&C$4&"') and (C = date '"&text($B$4,"yyyy-mm-dd")&"')"))
you can also put one formula in A5 as follows
=sort(query(arrayformula(split(flatten(Encoding!A4:A9&"~"&Encoding!B4:B9&"~"&Encoding!C4:C9&"~"&Encoding!D3:K3&"~"&Encoding!D4:K9),"~",true)),
"select Col4,sum(Col5) where Col3="&B4&" and (Col2 contains '"&C$3&"' or Col2 contains '"&C$4&"') and Col1="&C2&" group by Col4 label sum(Col5) ''"),1,0)
I have my current query below;
=QUERY({Source_1!B2:I;Source_2!B2:I;Source_3!B2:I},"select * where Col3 is not null",0)
I want to have all my data be combine to one to "All_Sheet" tab it works so far.
Now I need in Col A of my tab "All_Sheet" be included to all rows the Sheet Name like Source_1, Source_2 and so on.
Try this:
Add a calculated column
First build a range that contains the sheet name you want to reference. I did it by concatenating a range that is empty and the sheet name:
{N2:N&"Sheet1",Source_1!B2:I}
The above by itself won't work, because it needs to be told that it is an array. So we wrap it in ARRAYFORMULA():
ARRAYFORMULA({N2:N&"Sheet1",Source_1!B2:I})
Which gives a range that looks like this:
Then build up the rest of your query like this:
Sheet 1 | B2 Value | C2 Value | D2 Value | ...
Build our Query
Take the above and build up your multiple ranges and complete your query. Linebreaks for readability
=QUERY(
ARRAYFORMULA(
{
N2:N&"Sheet1",Source_1!B2:I;
N2:N&"Sheet2",Source_2!B2:I;
N2:N&"Sheet3", Source_3!B2:I
}),
"select * where Col3 is not null",0)
I am trying to set up a calendar-type to-do list on google sheets. I would like to be able to take a date from a certain cell on sheet 1, and use it to match up to a to-do list from another sheet (sheet 2) that corresponds with the same date that's at the top of the column, then transpose the data from sheet 2 onto sheet 1. Should I try to use a transpose function? Hlookup?
query function would work well:
=query(Sheet1!A:D,"select * where A = date '"&text(G1,"yyyy-mm-dd")&"' order by B,C,D ",1)
For ease, I've shown it on the same sheet.
More about query:
https://developers.google.com/chart/interactive/docs/querylanguage#language-clauses
Some alternatives:
=query(transpose(Sheet1!1:4),"select * where Col1 = date '"&text(A7,"yyyy-mm-dd")&"' order by Col2 ",1)
=transpose(query(transpose(Sheet1!1:4),"select * where Col1 = date '"&text(A7,"yyyy-mm-dd")&"' order by Col2 ",1))