Google Sheet Array formula Column result multiplication by cell value - google-sheets

=ArrayFormula({QUERY({'2020 BBVA IRHP'!A:O,'2020 BBVA IRHP'!D:D&"-"&'2020 BBVA IRHP'!D:D},"SELECT 'IRHP','BBVA','IRHP BVA','EUR',Col15,Col1,Col6,Col7,Col16,Col6*$T$1$ WHERE Col1 CONTAINS '2021'")})
I want to multiple the result of Col6 by an FX rate contained in the Sheet in Cell T1 .
What is the syntax in the formula to refer to cell T1 to make this work ?

The query statement is just a text string. You can modify it by cell values using string concatenation and manipulation.
To multiply every number in query() column 6 with the same multiplier that is stored in a spreadsheet cell, use this pattern:
...Col6 * " & T1 & " where...

Related

Counting over aggregated columns in Google Sheets

I have the yellow table shown below, and I'm trying to get the blue table, which aggregates columns B:F by value, and then counts the number of 'x' symbols for each row value of column A.
Is there some basic SQL/array magic formula to get this, please? There must be.
Use this new functions formula
=BYROW(B2:4, LAMBDA(v, COUNTIF(v, "=x")))
Used:
BYROW, LAMBDA, COUNTIF
v is the array_or_range
Update
={ A2:A4, BYROW(B2:4, LAMBDA(vv, COUNTIF(vv, "=x")))}
For fun
Update 02
=ArrayFormula(TRANSPOSE(QUERY({
QUERY(TRANSPOSE(IF(A1:4<>"x",A1:4,1)),
" Select * Where Col1 is not null ", 1)},
" Select (Col1),sum(Col2),sum(Col3),sum(Col4) Group by Col1 ", 1)))

Array of IMPORTRANGEs in Google Sheets

For this sample table:
A
B
C
D
E
1
Range!A1:C5
URL1
= Formula here
2
URL2
3
URL3
4
...
I have this working formula in C1:
={IMPORTRANGE(B1, A1); IMPORTRANGE(B2, A1); IMPORTRANGE(B3, A1)}
A1 contains the range to pull from the target Sheets.
Links to the target Sheets are found in column B.
(This is a simplified example. My actual Sheet has 21 entries in column B.)
Question:
If I will have to add/remove URLs in column B, I have to adjust the formula in C1 and add/remove IMPORTRANGEs.
I would like to have a formula that automatically adjusts to the entries in column B.
Solutions tried:
I tried this, but it did not work:
={JOIN("", ARRAYFORMULA(IF(LEN(B1:B), "IMPORTRANGE(""" & B1:B & """, """ & A1 & """); ", "")))}
The JOIN function returns a text that should be identical to what the array { ... } parses as a formula. But it doesn't. Wrapping it with INDIRECT also does not work.
Any suggestions on how I could make this work?
if by "working formula" you mean valid formula that returns data then only thing you can do is hardcode it like this:
=QUERY({
IFERROR(IMPORTRANGE(B1, A1), {"","",""});
IFERROR(IMPORTRANGE(B2, A1), {"","",""});
IFERROR(IMPORTRANGE(B3, A1), {"","",""})},
"where Col1 is not null", )
A1:C5 = 3 columns = {"","",""}
you can generate formula dynamically with arrayformula but the result will be always a text string and not active formula. tho if you wanna go this way you will need a script that will convert your text string into active formula. example:
https://stackoverflow.com/a/73119313/5632629
https://stackoverflow.com/a/61819704/5632629

Google Sheets : horizontal (row) conditional Arrayformula

I have row 1 containing some dates (undetermined number, because end formula will be a dynamic number) and I want row 5 to display the average of every column that has a date as a header.
Trying to have this array formula work :
arrayformula(iferror(
if(B1:1 = "",,
AVERAGE(
indirect(
SUBSTITUTE(ADDRESS(1,COLUMN(B1:1),4),"1","")
& 7 & ":" &
SUBSTITUTE(ADDRESS(1,COLUMN(B1:1),4),"1","")
)))))
I think I did isolate the problem in the arrayformula, I can't see where the problem lies with it ?
Here's a screenshot :
and here's the link to the spreadsheet :
https://docs.google.com/spreadsheets/d/1GbIWwv0lq6nVdn4dHkSO0-QqZYEPCwJtntCu8wcSd9Q/edit?usp=sharing
QUERY method:
=ArrayFormula(IF(B1:1="",,IFERROR(VLOOKUP(COLUMN(B1:1),QUERY(SPLIT(FLATTEN(TRANSPOSE(COLUMN(B7:7)&"♦"&B7:1000)),"♦"),"select Col1,avg(Col2) where Col2 is not null group by Col1 label avg(Col2) ''",0),2,FALSE),)))
MMULT method:
=ArrayFormula(IF(B1:1="",,IFERROR(MMULT(N(TRANSPOSE(ROW(B7:1000)^0)),N(B7:1000))/MMULT(N(TRANSPOSE(ROW(B7:1000)^0)),N(B7:1000<>"")),)))

Using sum within google spreadsheet query results in the word "sum" in many cells

I am trying to get the some of all values in row B that contain a certain value in row A. Pretty simple problem I guess.
Here is my query:
=QUERY('Sheet1'!$A$16:D, "Select sum(D) Where C contains '"&C5&"' ", -1)
But what that gives me is the actual word "sum" in all the fields where C contains the value.
So I get a lot of "sum" in almost all my rows.
Did the "sum" statement change for queries in google spreadsheets?
It looks like you are using more than one query formula: apparently there is a column with query, each referring to a cell such as C5. In this case there is no room for column label "sum" that the formula wants to insert: the output must be a single cell. Solution: change the column label to empty string with label sum(D) ''.
=QUERY('Sheet1'!$A$16:D, "Select sum(D) Where C contains '"&C5&"' label sum(D) ''", -1)

Have Arrayformula({Sheet1,Sheet2}) result in same colums ? (not side by side)

question about GoogleSpreadsheets.
Arrayformula({Sheet1,Sheet2})
this formula works for me cause it MERGES the content of the two sheets into a 3rd sheet (both sheets and destination sheet have the same structure/columnsCount)
BUT my problem is :
- everything taken from Sheet1 is put on columns A to W (the formula is indeed in cell A1)
- everything from Sheet2 is put in columns X to AT !
Is there a way to display first all the content of Sheet1 and THEN right-under it add all the lines from Sheet2
To 'stack' vertically, you need to use a semi-colon
=Arrayformula({Sheet1; Sheet2})
Note that his will also import blank rows. So to filter those out you may need to wrap a query() around it.
=QUERY (Arrayformula({Sheet1; Sheet2}), "where Col1 <> '' ")
or if the first col is numerical
=QUERY (Arrayformula({Sheet1; Sheet2}), "where Col1 is not null ")

Resources