Google Sheets query I can't select column "BY" [duplicate] - google-sheets

This question already has an answer here:
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "by" "BY "" at line 1, column 47 [duplicate]
(1 answer)
Closed 2 months ago.
This works:
=query(costMarkupLookup!A:CQ, "Select G,H,I,J,K,L,M,N,BL,BM,BZ,CA where BM is not null AND BZ > BM ",1)
If I add col BY in the Select, it doesn't work because it seems to be interpreting column BY as the keyword "BY":
=query(costMarkupLookup!A:CQ, "Select G,H,I,J,K,L,M,N,BL,BM,BY,BZ,CA where BM is not null AND BZ > BM ",1)
I get this error message when I try to include column BY:
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "by" "BY "" at line 1, column 40.
No doubt this is a bug, but is there a workaround?

Use back quote around those columns like-
=query(costMarkupLookup!A:CQ, "Select G,H,I,J,K,L,M,N,BL,BM,`BY`,BZ,CA where BM is not null AND BZ > BM ",1)
Again use back quote, not single quote.

or wrap your range into {} and use Col references
=QUERY({costMarkupLookup!A:CQ}, "Select Col7,Col8,.....

Related

How to put number in google sheet query

I want to do a query in google sheet something like:
=query({BY6:CH29},"
select Col2,sum(Col5*Col9*{144}/Col4),sum(Col5*Col10*{144}/Col4),sum(Col7*Col9*{144}/Col4),sum(Col7*Col10*{144}/Col4)
where Col2 is not null
group by Col2
order by Col1
",1)
How do I do it? I think the number 144 made the formula error
the query return #VALUE!
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "" " "" at line 2, column 21. Was expecting: ")" ...
Try this:
=query({BY6:CH29},"
select Col1, Col2,SUM(Col5)*SUM(Col9)*144/SUM(Col4),SUM(Col5)*SUM(Col10)*144/SUM(Col4),sum(Col7)*SUM(Col9)*144/SUM(Col4),sum(Col7)*SUM(Col10)*144/SUM(Col4)
where Col2 is not null
group by Col2,Col1
order by Col1
",1)

i am having issue using query function of google sheets

I am trying to query an XLSX file with the following statement =query($A$2:$E$34, "select E WHERE C = '1' AND A = 'Jun-21'"), in that case, C being a country number and A being the month and year and I am not able to get a value, I receive N/A saying that it has been completed with an empty result, even though there is a number matching criteria on the dataset
try:
=INDEX(QUERY(TO_TEXT(A2:E34), "select Col5 where Col3 = '1' and Col1 = 'Jun-21'"))

Query returning error Unable to parse query string for Function QUERY parameter 2: NO_COLUMN

I am currently working in the following spreadsheet
https://docs.google.com/spreadsheets/d/13KfjUhWSB-BjGyC1G8f8i8o4SPd1kFFLkjN7D6VY8Lk/edit#gid=993210576
In which I am importing data from another worksheet using IMPORTRANGE, and writing a QUERY to match the cells in column B, which correspond to a specific part number, to their corresponding cut quantity found in Column D of the imported sheet. The query I have written is as follows.
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28/edit#gid=473793446",
"FABRICATION LOG!A78169:K"), "Select Col3 where Col4 = "&B3&" limit 1", 0)`
And is returning the error message:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: WFR332703
I have used ImportRange for the sheet I am linking to in sheet1 of the spreadsheet linked above, and allowed access, so the error is not there.
Sheet1 is there to display the values returned for the IMPORTRANGE so that I can manually look up values I am expecting to get. Now for some of these cells, I expect to not get a value, as these will not be in the sheet I'm importing. But for others, I am expecting a numerical value, which is not being returned. I suspect this may have something to do with the fact that there is a mismatch between Datatypes since the entries in column b are both letters and numbers, but this is only a hunch with no actual facts to back it up. If anyone has any suggestions It'd be greatly appreciated.
first, paste this into some cell and connect you sheets by allowing access:
=IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28", "FABRICATION LOG!A1")
then use the formula:
=QUERY(IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28",
"FABRICATION LOG!A78169:D"),
"select Col3
where Col4 = '"&B3&"'
limit 1", 0)
if cell B3 is number use:
=QUERY(IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28",
"FABRICATION LOG!A78169:D"),
"select Col3
where Col4 = "&B3&"
limit 1", 0)
I came here because I had a query like:
=Query(Data, "select * where i < 70", 1)
What fixed it was changing to:
=Query(Data, "select * where I < 70", 1)
The column in the where clause needs to be upper case if its a letter higher than 'd'.

Parsing values from a column while excluding certain values from other column

I have two columns of values of which the second includes a subset of the first. I'm parsing partial matches from the first column with:
=query(A:A, "select A where A ends with 'x'")
It works fine. How would you modify it in order to exclude the shared values?
Here's an example:
A is where we're parsing from, B is the subset we want to discard, C would be the desired result:
filter values to exclude common values with column B
return only values ending in 'x'
Edit
To solve this, you first may need to exclude values from column B, then query result to match only pattern '%x'. Try this formula:
=QUERY(FILTER(A:A,REGEXMATCH(A:A,JOIN("|",FILTER(B:B,B:B<>"")))=false),
"select Col1 where Col1 like '%x'")
Edit #2
Special symbols for regular expressions are \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
If such symbols are met in your data, you need to escape them by \ in order to use regular expressions. So formula REGEXMATCH in this case won't work properly if column B contains special symbols. Possible solution is to replace them like this: [symbol] → [\symbol]. For example, to replece ():
=REGEXREPLACE(text ;"(\(|\)|\*)";"\\$1")
Try using this formula in column C to get the result:
=QUERY(FILTER(A:A,REGEXMATCH(A:A,
REGEXREPLACE( JOIN("|",FILTER(B:B,B:B<>""));"(\(|\)|\*)";"\\$1"))=false),
"select Col1 where Col1 like '%x'")
Original answer
may be using not keyword will work:
=query(A:A, "select A where not A ends with 'x'")
the same as:
=query(A:A, "select A where not A like '%x'")

Group the data in one column per the values in another column

I have data something as below
email id subject of interest
ramesh#axito.com Java,C++
mnp#axito.com VB
ramesh#axito.com Python
mohan#axito.com Java,C++
mnp#axito.com JS
rohan#axito.com C#
But I need it in the format as below-
email id subject of interest
ramesh#axito.com Java,C++,Python
mnp#axito.com VB,JS
mohan#axito.com Java,C++
rohan#axito.com C#
Can someone please tell me how can I do this?
First, create the list of unique email addresses with =unique(A2:A). Suppose this is done in column C.
Then in cell D2, enter =join(",", filter(B$2:B, A$2:A=C2)) and drag this formula down columd D.
Explanation: filter keeps only the entries from column B with matching email; join joins them into a comma-separated list.
Try using query function:
=QUERY({A:B,A:B},"select Col1, Count(Col2) where Col1 <> '' group by Col1 pivot Col4")
Also try this formula, this is single formula solution:
={UNIQUE(FILTER(A2:A,A2:A>0)),TRANSPOSE(
SPLIT(
", "&join(", ",
ARRAYFORMULA(
if(query(A:B,"select A where not A is null order by A",0)=
query(A:B,"select A where not A is null order by A limit "&COUNT(query(A:B,"select A where not A is null",0))-1,1),"","|")
& query(A:B,"select B where not A is null order by A",0)
& " "
)
)
,", |",0)
)}

Resources