Google sheets query - I would like to return a column, but if cells in the column are empty return cells in another column instead - sql

Kinda new at this, struggling with a solution.
So currently my formula looks like this:
=Transpose(Query(importrange("1XlxiJwGNEEgeV7qAbN4QXR1vustupeUMs5tOLI8qm54","2020 LNA!A:K"), "select Col8 where Col2 contains '"&P136&"' AND Col8 is not null offset 1"))
Col2 is my criteria and remains constant. What I'm looking to do is have the formula return the cell in Col9 if the cell in Col8 is empty. If the cell in Col8 is not empty it will just return as is.
Col8 is not null is to prevent returning empty spillover rows after the data.
Ideally I would use the case function but that isn't present for Sheets. Would love to hear any input, do let me know if more info/clarity is needed as well.
EDIT: Added pictures for reference. Image 1 is a separate workbook, Image 2 is desired output (E2:J2) with D1 as criteria
enter image description here
enter image description here

try:
=TRANSPOSE(QUERY(FLATTEN(QUERY(IMPORTRANGE(
"URL_or_ID_here", "2020 LNA!A2:C"),
"select Col2,Col3 where Col1 = '"&A1&"'", 0)),
"where Col1 is not null", 0))

Related

spreadsheet missing data for corresponding cells

I have a problem with missing data of corresponding column.
Column A has unique value which corresponds to specific cities in Col B. But few cells in col B is empty. It is long spreadsheet. How to fill col B from the values of corresponding col A automatically?
enter image description here
You can use if condition available with syntax ISBLANK().

How to query results that don't contain the #N/A error in Google Sheets

I am trying to query results that don't contain #N/A results from another sheet in the same Google Sheets WorkSheet.
I have tried this formula but it won't work
=QUERY('Table 1'!A2:G500, "Select F Where G <> '#N/A'")
Tried several other ways but still in vain.
I need to select Column F where column G does not contain #N/A.
Please help if you might know how to go about this.
try like this:
=QUERY('Table 1'!A2:G500, "select F where not G contains '#N/A'", 0)
or like this:
=ARRAYFORMULA(QUERY(IFERROR('Table 1'!A2:G500), "select Col6 where Col7 is not null", 0))

How to join the value of cells of a column, but only if a condition based in an other column is met

In record mode, is it possible to join the value of cells of a column, but only if a condition based in an other column is met ?
Example :
With those data, in each record, join the values in col3 only for the rows where col2="yes"
Expected result :
Here is a solution in Python/Jython:
col2 = row.record.cells.col2.value
col3 = row.record.cells.col3.value
return ";".join([x for x,j in zip(col3,col2) if j == "yes"])
For Grel, the best solution is probably something like this (if you like russian dolls):
forEachIndex(row.record.cells.col3.value, i, v, if(row.record.cells.col2.value[i]=="yes", v, null)).join(";")
It is also possible to do that without formulas:
Switch to row mode
Text facet on col2, select the "yes".
On col3 (or a copy of col3): Edit cells / Join multivalued cells
On col3 again (or your copy of col3): Edit cells / Fill down

Moving tuple of cells using VBA script

I have a bit strange situation in Excel. It looks like this
Col1 Col2 Col3
A 2 2
A 2 3
A 2 4
B 2 3
What I want to do is to have a VBA script which will make something like this. The "A" or index from Column 1 is the one that should match.
Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9
A 2 2 A 2 3 A 2 4
B 2 3
I tried moving around VBA but with no results. I can't wrap my head around creating a tuple with those cells (there is like 50 000 rows). I want this to work on every row and in the end produce such effect as presented.
There are no tuples in VBA, but there are class modules, i.e. classes that can be used instead. For example, you can add a class module MyTuple with 3 public fields:
Option Explicit
Public Col1 As Variant
Public Col2 As Variant
Public Col3 As Variant
Then you can instantiate your variable and use it like this:
Dim t As MyTuple
Set t = New MyTuple
t.Col1 = "..."
t.Col2 = "..."
t.Col3 = "..."

How to merge the results of a number of cells in excel, so that a yes in any one of the input cells will evaluate to yes in a single output cell?

I have a spreadsheet that looks something like this:
Col1 Col2 Col3 Col4
yes no no no
no yes no no
no no no no
no no no no
How can I combine these results so that Col5 will equal "yes" if there is a "yes" in any of the cells in Col1-4 and only equal "no" if every cell in a row from col1-4 equals "no"?
So in this example the output should look like this:
Col1 Col2 Col3 Col4 Col5
yes no no no yes
no yes no no yes
no no no no no
no no no no no
(I am using a mac with Excel version 15.29)
I'd go with:
=IF(COUNTIF(A2:D2,"yes")=0,"no","yes")
Pretty straight forward IF with OR :
=IF(OR(A1="yes";B1="yes";C1="yes";D1="yes");"yes";"no")
or
=IF(OR(A1="yes",B1="yes",C1="yes",D1="yes"),"yes","no")