How do I reference one cell created in ARRAYFORMULA from another? - google-sheets

Let's say I'm using ARRAYFORMULA to generate values (whitespace is for readability):
=ARRAYFORMULA({
Sheet1!A1:C,
Sheet1!A1:A * Sheet1:B1:B,
Sheet1!A1:A * Sheet1:B1:B + Sheet1!C1:C
})
The first 3 cells are directly from Sheet1.
The 4th cell is a formula using the values from the first 2 cells.
The 5th cell is a formula using the value from that 4th cell, and then adding the 3rd cell.
Instead of needing to re-calculate the 4th cell in the 5th cell, is there a way to reference the result of the 4th cell in the 5th cell?

No, there is no way to reference a column of virtual array {} within the same array. Two workarounds are:
Create the column A*B+C using a second array formula, which references the output of the first
or,
Wrap the output of arrayformula in a query which can reference the columns as Col1, Col2, ...
Example:
=query(arrayformula({A1:C, A1:A*B1:B}), "select Col1, Col2, Col3, Col4, Col4+Col3 label Col4+Col3 ''", 0)

Related

Arrayformula to calc sum for dynamic offset range

I'm trying to calculate values with an arrayformula, based on the last 14 days (the last 14 rows, since every row is 1 day).
I want N110:N to have the values (in example: sum) from, let's say, I96:I110.
Means, the values in N110 should be sum(I96:I110). For N111 it should be sum(I97:I111) etc.
I have something like = ARRAYFORMULA("I"& Row(I110:I)-14 & ":I" & Row(I110:I)) which returns
I96:I110
I97:I111
I98:I112
...
in each row.
I cannot wrap this into the arrayformula, since Indirect() is not working here and is returning only the first value.
I also tried with offset, which led to the same result.
Basically I'm trying to use an arrayformula to calc values by a dynamic offset range with a fixed size (14).
I could solve it with google apps script, but I want to try with arrayformula.
try:
=INDEX(IFNA(VLOOKUP(ROW(A1:A),
QUERY(SPLIT(FLATTEN(ROW(A1:A)&"×"&ARRAY_CONSTRAIN(
SPLIT(FLATTEN(QUERY(TRANSPOSE(IF(ROW(A1:A)<=TRANSPOSE(ROW(A1:A))=TRUE,
TRANSPOSE(A1:A)&"×", )),,9^9)), "×"), 9^9, 14 +N("14 day window"))), "×"),
"select Col1,sum(Col2)
where Col2 is not null
group by Col1"), 2, )))
Make sure that N110:N is empty, and then place the following formula in N110:
=ArrayFormula(IF(I110:I="",,SUMIF(ROW(I96:I),"<="&ROW(I110:I),I96:I)-SUMIF(ROW(I96:I),"<="&ROW(I110:I)-15,I96:I)))
This formula assumes that there are no blank cells interspersed between numbers in I96:I (though there may be blank cells after the number list runs out).
Essentially, this sums all cells in in the range up to the current row and then subtracts the total of all cells in rows prior to "15 cells back" as marked from the current cell.

Google Sheets QUERY IMPORTRANGE is merging first and second rows

In a company that I work for, I have two Google Sheets. In one of them (let's call it "Destination"), I am trying to use QUERY+IMPORTRANGE to bring the values from the other (let's call it "Origin").
My problem is that in the first row of Destination, the values of the cells are a merger of the values of the first and second rows of Origin.
For example, the value in cell B1 of Destination should be the value of cell B1 in Origin. However, it is actually the values of B1 and B2 of Origin. The same happens for every single cell in the first row.
Origin B1: milk
Origin B2: water
Destination B1 (desired value): milk
Destination B1 (value that is appearing): milk water
The only problem is with the first two rows of Origin. All the other rows are fine (meaning that row 2 in Destination is row 3 of Origin, row 3 in Destination is row 4 of Origin, and so on).
I am using the following formula:
=QUERY( {IMPORTRANGE("URL";"'Sheet1'!A1:CW")} ; "Select * where Col1 is not null")
I have discovered that when I use A1:AO as the interval in IMPORTRANGE, the problem doesn't happen. However, when I use it from A1:AP and onwards, the problem appears.
Could someone help me with this problem?
change your query to specify 1 for the header parameter:
=QUERY( {IMPORTRANGE("URL";"'Sheet1'!A1:CW")} ; "Select * where Col1 is not null",1)
or 0 if i'm misunderstanding the data layout...
=QUERY( {IMPORTRANGE("URL";"'Sheet1'!A1:CW")} ; "Select * where Col1 is not null",0)

First non blank cell in row as an array for the column

First non blank cell in a row as an array formula for the whole column.
None of these seem to work.
=ArrayFormula(QUERY(transpose(V2:Y),"Select Col1 where Col1 is not null limit 1",0))
=ArrayFormula(index(V2:Y,MATCH(FALSE,ISBLANK(V2:Y),0)))
=ArrayFormula(VLOOKUP("*", V2:Y, 1,FALSE))
https://docs.google.com/spreadsheets/d/1S3svXvdC45VqCFu1710_VrEuo4kWo0kKe6CuxbpnqnI/edit?usp=sharing
try:
=IFERROR(INDEX(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(A2:D),,99^99))), " "),,1))

Copy Data from other Sheet and insert it with an emty cell (column) every other cell (with image cells)

I want to copy data from another Sheet that doesn't matter if it's with {MySheet!A1:A4} or with IMPORTRANGE or whatever. And insert the Data into another Sheet transposed but inserting an empty column or cell every other row (so basically skip would work). To make it a bit more difficult I'm having pictures in some of the rows so sometimes there is no text but only inserted pictures.
So if my original table would be
A1 (Content="TextfromCellA1"),
A2 (Content=ImageInCell1),
A3 (Content="TextfromCellA3"),
A4 (Content=ImageInCell2)
I want to print the cells like this
A1 (Content="TextfromCellA1"),
B1 (Content=empty),
C1 (Content=ImageInCell1),
D1 (Content=empty),
E1 (Content="TextfromCellA3"),
F1 (Content=empty),
G1 (Content=ImageInCell2),
I for sure can start with:
=TRANSPOSE(MySheet!A1:A4)
I tried Querys and everything but couldn't get it to work.
Here's one thing I tried as well, but it will give me an error message as i can't concat the image that is in the cells :/
=ARRAYFORMULA(SPLIT(TEXTJOIN("🐇",1,IF(MOD(ROW(A1:A20),5)=0,A1:A20&REPT("🐇 ",3),A1:A20)),"🐇"))
For the simple, may be like this:
={A1,"",A2,"",A3,"",A4}
Using Query and transpose:
=query({Transpose(A1:A4),"","",""}, "Select Col1, Col5, Col2, Col6, Col3, Col7, Col4")

Arrayformula to compare two columns and skip blank cells

I have two columns on two different sheets with a long list of values; I'm trying to compare these two columns to check if an entry in the first one exists in the second one. In the first column there are also blank cells.
I tried different formulas but all of them is returning a value for blank cells, instead of a blank cell.
These are the formulas I tried:
=arrayformula(iferror(if(match(A1:A,AnotherSheet!A1:A,0),"yes"),"no"))
=query(arrayformula(iferror(if(match(A1:A,AnotherSheet!A1:A,0),"yes"),"no")), "Select * where Col1<>''")
=query(arrayformula(iferror(if(match(A1:A,AnotherSheet!A1:A,0),"yes"),"no")), "Select * where Col1 is not empty")
All of them is returning "no" for blank cells in the first column, I would like to have a blank cell instead. Thank you
=ARRAYFORMULA(IF(LEN(A1:A), IFERROR(IF(MATCH(A1:A, AnotherSheet!A1:A, 0), "yes"), "no"), ))

Resources