QUERY Function Question Regarding WHERE clause - google-sheets

I have a query where I am trying to match the range value with the value that is in the first column (A) of the current row:
=QUERY(IMPORTRANGE("https://URL.com", Spreadsheet!A:Z), "SELECT COl4 WHERE Col1 = "' & CONCATENATE('A', ROW()) & '")
So essentially, I am trying to select the value of col4 if col1 matches the value of "A235" or A + whatever the current row is.
However the Concatenate part doesn't seem to be working (Formula parse error) and if someone could point me in the right direction, it will be awesome.
Thanks!

Repeating a working solution from my comment.
Try this:
=QUERY(IMPORTRANGE("https://URL.com", Spreadsheet!A:Z), "SELECT COl4 WHERE Col1 = '" & A:A & "'")

Related

Query Importrange does not return any output

quick question, please
I want to do a query import range formula in Google Sheets with three criteria:
1: E-mail
2: Number of the week (e.g: 2)
3: The data column
Ive already allowed the sheets to share information but I'm getting a "Query completed with an empty output." message, even thought the cell has an imput.
Formula: =QUERY(IMPORTRANGE("linkofthesheet";"Indicadores!A9:L123");" SELECT Col3 WHERE Col1 = '"&B4&"' AND Col2 = '"&C10&"'")
I was trying before to use a vlookup together with it but a friend told me it would be redundant. Please, what do you guys think it could be the issue?
2: Number of the week (e.g: 2)
If cell C10 contains a number, you should leave the 'quotes' out, like this:
=query( importrange("...put sheet id here..."; "Indicadores!A9:L123"); "select Col3 where Col1 = '" & B4 & "' and Col2 = " & C10, 0)

How to filter this criteria based vertically combined queries blank row?

I'm using this to successfully (or almost) query multiple columns into 01 based on a criteria. This, however, shows a blank row I can't seem to get rid of.
=iferror({
query({Orders!A:FF}, "select Col144 where Col7 matches '"& P4 &"' and not Col144 contains '#N/A' and not Col144 matches '-' and Col144 is not null");
query({Orders!A:FF}, "select Col151 where Col7 matches '"& P4 &"' and not Col151 contains '#N/A' and not Col151 matches '-' and Col151 is not null");
query({Orders!A:FF}, "select Col162 where Col7 matches '"& P4 &"' and not Col162 contains '#N/A' and not Col162 matches '-' and Col162 is not null")
},"")
I've tried filter it in the query criteria set, but it still shows.
This is current result, with always this blank row:
How to accomplish it?
Here's some mock data for tests.
Thank you!
See the new tab called MK.Help where you will find this formula to show only items with variance 2.
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(D2:I2&"|"&A4:A6&"|"&B4:B6&"|"&D4:I6),"|",0,0),"where Col2 = 2"))
The query(split(Flatten( technique has become the most common way to "unpivot" data since the Flatten function was discovered several years ago hidden in the back end of Google Sheets.
If I understood your question correctly you just want to remove the blank rows from the returned Query. You can try adding another Query instead of filter to remove the blanks.
From your sample sheet I edited the existing formula
Try:
=QUERY({QUERY({D1:G10},"select Col2 where Col1 matches '"&B2&"'",0);QUERY({D1:G10},"select Col3 where Col1 matches '"&B2&"'",0);QUERY({D1:G10},"select Col4 where Col1 matches '"&B2&"'",0)},"Select Col1 where Col1 is not NULL")
Result:
Let me know if this works for you.

How to use several conditions with QUERY + IMPORTRANGE in google sheets?

I'm trying to get unique values by using this formula:
=UNIQUE(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/here goes link","Income!2:8000"),"Select Col15,Col16, Col26 where Col3=" & "'" & B2 & "'"))
And I'm getting the result that I need. The only problem is that I'd like to add an additional condition to it and have no idea how to do it.
I'd like this formula to filter values not only based on Col3 but based on another one, for example, Col3 = B2 and Col2 = A2.
Does anyone have any idea how to do it?
Thank you in advance!
Update: based on the sheet and the data format you have shared, this formula should work:
=UNIQUE(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1pXFIWzeHcJPQJtjUqOdgi2FusNGEUoeGlA5rLGNuKLQ/edit#gid=0","data!2:500"),"Select Col15, Col16, Col26 where Col3 = '"&B2&"' and Col2 = date'"&TEXT(DATEVALUE(A2), "yyyy-mm-dd")&"'")
You can use and with where to check for multiple conditions.
=UNIQUE(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/here goes link","Income!2:8000"),"Select Col15, Col16, Col26 where Col3 = '"&B2&"' and Col2 = '"&A2&"'"))

How to use ARRAYFORMULA in query where clause?

In cell C1:C of my table I got 6 rows with ticket id's. I like to search different spreadsheets to search for those ticket id's and calculate the total hours spent on that ticket.
I have it working using the following formula:
=QUERY({IMPORTRANGE("SPREADSHEETID";"B3:B")\ARRAYFORMULA(TO_PURE_NUMBER(IMPORTRANGE("SPREADSHEETID";"F3:F")-IMPORTRANGE("SPREADSHEETID";"E3:E")))};"SELECT SUM(Col2) WHERE Col1 = '"&C1&"' GROUP BY Col1 LABEL SUM(Col2) ''")
In this example, C1 is where the ticket ID can be found.
Now I thought I could just wrap QUERY in a ARRAYFORMULA and use C1:C instead of just C1 but that won't work. Now I could just copy and paste the above formula in every cell but there must be a cleaner way.
ANSWER
I used the following formula to make it work, thanks to Max's answer below.
=QUERY(
{
IMPORTRANGE("SPREADSHEETID";"B3:B")\
ARRAYFORMULA(
TO_PURE_NUMBER(
IMPORTRANGE("SPREADSHEETID";"F3:F") - IMPORTRANGE("SPREADSHEETID";"E3:E")
)
)
};
"
SELECT Col1, SUM(Col2)
WHERE Col1 = '" & JOIN("' OR Col1 = '";FILTER(C:C; C:C <> "")) & "'
GROUP BY Col1
LABEL SUM(Col2) ''
")
Sample formula is:
=QUERY({A:B},"select * where Col1 = '"&JOIN("' or Col1 = '",FILTER(D2:D,D2:D<>""))&"'")
No, one cannot create an array of query strings and use arrayformula(query(...)) to run them all at once.
Alternative: instead of
SELECT SUM(Col2) WHERE Col1 = '"&C1&"' GROUP BY Col1 LABEL SUM(Col2) ''
use the query
SELECT Col1, SUM(Col2) GROUP BY Col1
elsewhere on the sheet, and then use vlookup to look up the sum for each value of Col1 that you want. vlookup can be used inside of arrayformula like this:
=arrayformula(vlookup(C1:C10, E:F, 2, 0))
looks up each of values in C1..C10 in the column E (exact match required) and returns the corresponding value in column F (2nd column of the searched range).

Concatenate or insert a number into a QUERY() string in Google Sheets

I am trying to use QUERY() to call a column of data from one sheet to another based on the contents of other columns. The code below works just fine.
=query(Data!$A1:$Y15), "select Col7 where Col1 starts with """&E$2&""" ")
However, I want to copy this data and have Col7 change to match the row of the cell that the formula is in + 1. It should be something like this (the formula is in cell F6):
=query(Data!$A1:$Y15), "select Col"""Row(F6) + 1""" where Col1 starts with """&E$2&""" ")
How can I concatenate or insert a number into a query string? I do need to use query due to some other constraints I simplified out of this example.
Just use & for concatenation, the way you did around E$2.
"select Col" & Row(F6) + 1 & " where Col1 starts with """ & E$2 & """ "
I would also use single quotes around the string from E$2, because they don't need to be escaped by doubling:
"select Col" & Row(F6) + 1 & " where Col1 starts with '" & E$2 & "'"
Also, Row(F6) could be simply Row() which returns the row of the current cell.

Resources