Google Sheets QUERY IMPORTRANGE is merging first and second rows - google-sheets

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)

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.

ARRAYFORMULA with a range that changes from cell to cell

I have a list of items in column A. In column B I want to use an ARRAYFORMULA function that will bring the serial number of each item to appear - 1 next to the first item, 2 next to the second etc.
This formula works fine but breaks when there are blank rows:
=ARRAYFORMULA(IF(LEN(A2:A),ROW(A2:A)-1,""))
This formula works nice but I need to drag it which I don't want to do. This is why I want it as an ARRAYFORMULA (note that I fix the range to always start from A$1 so only the range changes in size as I drag it further down).
=IF(LEN(A2),COUNTA(A$1:A2),"")
What I need is basically something that will work like the 2nd formula but with an ARRAYFORMULA.
Here's a spreadsheet to make it clearer (col A is the list, col C is function 1 and col D is function 2):
https://docs.google.com/spreadsheets/d/17qVGwvFJVrxdwkgmVQatH3Urpjl0_xB8EGqUsPVIwl8/edit?usp=sharing
In F2 I entered
=ArrayFormula(if(len(A2:A), countifs(A2:A, "<>", row(A2:A), "<="&row(A2:A)),))
See if that works for you?

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")

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

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)

Copy cell from every nth row

I'd like to grab the names in every person's name from this google spreadsheet and put it into a new column. The names will be every nth row.
Alternatively, also try:
=filter(A2:A, mod(row(A2:A)+1,3)=0)
In B2 please try:
=offset(A$1,3*(row()-1)-2,)
As the formula is copied down the offset row relative to A1 increases by three, with no column offset. In the second (starting row) 3*(2-1)-2 is 1 so the A2 value is returned. In the second output row 3*(3-1)-2 returns 4, so the A5 value is returned, and so on.

Resources