I'm trying to write a query that looks compares strings within a cell on two different pages. This is the query I have written but it says unable to parse query string because there is no column b4.
=QUERY(Teams!B:F, "select F where B = B4", 0)
Note column B is on a different page than B4.
if B4 is number do:
=QUERY(Teams!B:F, "select F where B = "&B4, 0)
if B4 is not number do:
=QUERY(Teams!B:F, "select F where B = '"&B4&"'", 0)
Related
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 a Google Sheets database that I want to query. I want the query to be based on data in columns B, C, and D and return all data if the conditions are met. I have input cells for the search criteria for those three columns, and I'd like the query to do the following:
Ignore search criteria where there is no value entered in the search cell
Use AND logic where there is a value in a given cell
For example, search criteria in input cells:
B = "1"
C = Blank
D CONTAINS "the"
I want the query to return data where C is anything and B = "1" and D CONTAINS "the".
Another example:
B = "1"
C = "E"
D CONTAINS "the"
I want the query to return data where all three conditions are met
I'd like D to not be null in all cases.
I'm having trouble incorporating the empty criteria into the query. I've tried dynamically using AND/OR depending on whether there's data in a given search cell, but I can't get it to work.
So, I created a crazy-long query to account for all possible combinations with B, C, and D. This works, but I want to incorporate more search criteria, and this equation becomes exponentially more complicated with 4, 5 or more search criteria.
Here is an image of the query input and query results for the first example above (I'm not sure why some of the values in the Name column don't contain "the").
Image of Query Sheet
And here's an image of the database that I'm querying against:
Image of Database Sheet
Here is the equation I'm using:
=if(and(B4="",C4=""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and D IS NOT NULL order by D asc",1),
if(and(B4<>"",C4=""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and B matches '"&B4&"' and D IS NOT NULL",1),
if(and(B4="",C4<>""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and C matches '"&C4&"' and D IS NOT NULL",1),
if(and(B4<>"",C4<>""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and B matches '"&B4&"' and C matches '"&C4&"' and D IS NOT NULL",1),
if(D4="",query(DATABASE!A1:E,"SELECT * WHERE B matches '"&B4&"' "&IF(AND(B4<>"",C4<>""),"AND","OR")&" C matches '"&C4&"' and D IS NOT NULL",
1),FALSE)))))
My ask: I'd like to simplify this equation so that it can be extended to multiple search criteria (more than 3). Thank you for your help!
Try this:
=QUERY(
DATABASE!A:E,
"WHERE D IS NOT NULL"
& IF(B4 = "",, " AND B = " & B4)
& IF(C4 = "",, " AND C = '" & C4 & "'")
& IF(D4 = "",, " AND D CONTAINS '" & D4 & "'")
& " ORDER BY D",
1
)
I have a tab call (Data Import) where I have the whole raw data imported in google sheets, in the next tab I have my query that looks as below;
This is the query -> =QUERY('Data Import'!$I1:$O, A1, 1)
A1 is equal to -> ="SELECT K, O, J WHERE J >= "&F1&""
F1 is equal to -> 44196
The result I get is only the first row, but I want all the rows that contains the same date which are a total 25 plus the header with the column names.
Does anyone figures what I am doing wrong?
try in A1:
=QUERY('Data Import'!I1:O,
"SELECT K,O,J WHERE J >= "&F1*1, 1)
you could also solve it like:
=QUERY('Data Import'!I1:O,
"SELECT K,O,J WHERE J >= date '"&TEXT(F1, "yyyy-mm-dd")&"'", 1)
I've been using the following function:
=query(Sheet1!A2:D," select A, B, C where A matches '"&JOIN("|", A2:A)&"' and D matches 'yes'")
Is there anyway that I can make is so that every row that starts with a match will be added a comma separated list in which each column occupies one cell with no duplicates as shown in sheet3.
https://docs.google.com/spreadsheets/d/1YDxIUnZzzYde9hcexPoDegv4HBuiUwk2wLKSXazu9hE/edit?usp=sharing
Sheet 2 has the function that I used and the result.
It is not entirely clear what you want to do, but try this. In Sheet1 in E2 put this combining Col A and D:
=arrayFormula(A2:A & if(isBlank(D2:D),""," ") & D2:D)
In F2 combine Col C and D with this:
=arrayFormula(B2:B & if(isBlank(C2:C),"",",") & C2:C)
In G2 find the unique values from Col F with this:
=UNIQUE(E2:E)
In H2 put this and drag the formula down:
=join(",",query(E2:F,"select F where E contains '"& G2 &"'"))
Hide Cols E & F