Query continues to select rows despite 'where not null' - google-sheets

I'm using a query command in google sheets to take the left variable of a text string, convert it to a number and sum it with other columns. When I attempt to use a query command of where Col1 is not null it continues to pull each row leaving a sheet full of zeros. What am I missing? Here's the full formula
=Query(ArrayFormula(value(left(T2:AC))),"select Col1+Col2+Col3+Col4+Col5+Col6+Col7+Col8+Col9+Col10,Col9 where Col1 is not null label Col1+Col2+Col3+Col4+Col5+Col6+Col7+Col8+Col9+Col10 'Total', Col9 'Q9'")

VALUE converts empty strings ("") to 0, as you can see on of the examples from the official Docs.
Because of this, before using VALUE to a cell, you should first check if the cell is empty. One option would be to use ISBLANK:
=ARRAYFORMULA(IF(ISBLANK(E2:F),,VALUE(LEFT(E2:F))))

Related

Finding the first value in a row and getting the address using ArrayFormula

in this example table, I want to get the first "failed" or "passed" from result 1, 2, and 3 column. I already made a formula to get the first mentioned value using:
=IF(C2=C2,CELL("address",INDEX(D2:F2,MATCH(C2,D2:F2,0))),)
which works fine (the column result is from that formula)
But when I'm trying to use ArrayFormula on the formula, it only shows the first row value only. my ArrayFormula is like this:
=ArrayFormula(IF(C2:C4=C2:C4,CELL("address",INDEX(D2:F2,MATCH(C2:C4,D2:F2,0))),))
i think its because the INDEX and MATCH doesn't update as it goes down, any idea how to fix this?
Sheets link: https://docs.google.com/spreadsheets/d/1oFTZHGd9PKpfZ9QXWvTshorEOGFxmD1cpeeQ9bIOYh8/edit?usp=sharing
You could use a query to get the minimum column matching the value in column C for each row in D to F:
=ArrayFormula(lambda(a,address(index(a,,1),index(a,,2)))
(query(split(flatten(if(C2:C="",,if(D2:F=C2:C,row(C2:C)&"|"&column(D2:F),))),"|"),"select Col1,min(Col2) where Col2 is not null group by Col1 label min(Col2) ''")))
Or alternatively you can use a formula similar to your original one with Byrow:
=ArrayFormula(if(C2:C="",,byrow(C2:F,lambda(r,CELL("address",INDEX(r,1+MATCH(index(r,,1),index(r,,2):index(r,,columns(r),0))))))))

Google Sheets Query Error: Query Not Returning proper Array value when a condition is TRUE

I'm trying to solve why one of the Google Sheets I maintain is failing to operate properly. I've isolated that the issue is with a query
QUERY(Import_MJL!A:BU, "select A where AJ> 0")
For reference the Import_MJL sheet is a static database. The AJ column holds a currency value. When performing an IF function of that column, it returns as TRUE as seen here
if(Import_MJL!AJ2 > 0,1,0)
What could be the reason that the query is not recognizing when my AJ Column is above 0 ?
Screenshot for bellow reference. Row 1 holds the code & row 2 holds the Results (The B2 Cell should result in an array whose length is over 10K but only returns the header. The Import_MJL!AJ2 cell has value 38K and should be a result of the cell on B2)
Screenshot of code and results
Thanks for the time y'all!
Chances are that Import_MJL!AJ2 does not contain a number but the text string $38,738.00 that only looks like a number. Many spreadsheet functions will automatically convert such values into numbers, but query() will not.
You can check whether a value is actually a number with the isnumber() function.
Here's a quick fix to try:
=arrayformula(
query(
{ Import_MJL!A1:AI, value(Import_MJL!AJ1:AJ), Import_MJL!AK1:BU },
"select Col1 where Col36 > 0",
1
)
)

Google Sheets Query Coalesce?

is there any query syntax that woks like coalesce in google sheets?
if i have a source like pict below
the result i want is only getting id and time if status is true, but the time is only exist in one col either in check column or report column
so the result would be like this...
I tired this but doesn't work
=QUERY(A1:D4, "SELECT A, COALESCE(B, C) WHERE D = TRUE")
any ideas or workarounds?
Thanks
try:
=ARRAYFORMULA(IFERROR(SPLIT(FLATTEN(QUERY(TRANSPOSE(
ARRAY_CONSTRAIN(IF(D2:D=TRUE, {A2:A, IF(B2:C="",,"×"&B2:C), D2:D}, ), 9^9,
COLUMNS(A:C))),, 9^9)), "×")))
A very short one just for the special case of 2 columns where you know that only one of them is populated and they are dates:
=ArrayFormula(to_date(if(D2:D,B2:B+C2:C,)))
Maybe the simplest formula which behaves like coalesce would be
=iferror(if(D2,hlookup(9^9,B2:C2,1,true),))
It's just a pull-down formula but will pick up the first non-blank column from a range of columns containing numbers or dates. If the columns are all blank, it returns blank.
You can take advantage of the either or situation and concatenate the 2 columns.
=filter({A2:A,concat(B2:B,C2:C)},D2:D)
Also see local array and filter
Add a column after Status call it Time (column E), whereas each formula follows this format (assuming your table starts at A3:E)
=if(A4="","",if(B4<>"",B4,C4))
Now query A3:E like so,
=query(A3:E,"Select A,E where D=TRUE")
you can use something like this:
=QUERY(transpose(B1:H1),"Select Col1 where Col1 is not null limit 1",0)
This transposes the row into a column, queries all non-null values from that column, and then set limit 1 to return the first value. So essentially you are selecting the leftmost non-empty value from your row.
I can't take full credit for this, I must have gotten it somewhere else... but it's in one of my sheets.

Google Sheets bug? query completed with an empty output

I have a named range in Google Sheets and I am making a simple query which should return a value but it doesn't work:
=QUERY(range2,"SELECT B WHERE A contains 'test' ")
It should return "2" but it sais that the query completed with an empty output.
Is it a bug?
actually, QUERY is known to behave like this and its caused by a superiority of numeric values over text string values in a given dataset. fix would be to select columns A and B and format them as Plain text
another approach would be to convert dataset within formula like:
=ARRAYFORMULA(QUERY(TO_TEXT(A:B),
"SELECT Col2
WHERE Col1 contains 'test'"))

#Value Error on Query - Google Spreadsheet

I'm trying to combine the data in two sheets into another sheet by using the below code:
=UNIQUE(ArrayFormula(query({filter('Sheet1'!A2:B,NOT(ISBLANK('Sheet1'!A2:A)));filter('Sheet2'!A2:B,NOT(ISBLANK('Sheet2'!A2:A)))},"order by Col1")))
It works perfect if both sheets have at least 1 row filled but if either of the tabs are empty, then I receive #Value.
How can I fix this code so that it still works if either of the tabs are empty?
Filter throws an error instead of returning no values, a property that is very annoying in this case.
Since you're already using the query command why don't you try this, either one or both ranges can be completely empty.
=UNIQUE(ArrayFormula(query(
{Sheet1!A2:B; Sheet2!A2:B},
"WHERE Col1 is not null order by Col1")))
Alternatively if Col1 contains always strings a shorthand is Col1 <> ''

Resources