Arrayformula & Counta - google-sheets

Goal: a formula in row P2 that counts instances of data from F2:M2 that is also populated down all of P. Here's the example.
I have been trying to get an array formula that does it so that if I want to change things I can just edit P2 instead of doing that all the way down.

Try this:
=arrayformula(
iferror(
1 / ( 1 /
countif( sign(len(F2:M)) & "-" & row(F2:M), "1-" & row(F2:M) )
) )
)

Related

What aggregation function to concatenate string like sum() for number in google sheet?

Basically I would like to convert the following table
Name
Team
A
X
B
X
A
Y
B
Z
C
X
A
Z
to
Name
Team
A
X,Y,Z
B
X,Z
C
X
It is something like sum(B) group by A but for strings rather than numbers
What kind of Google Sheet formula or Query() can do this? Thanks!
=ArrayFormula(
REGEXREPLACE(
SPLIT(
TRANSPOSE(
QUERY(
QUERY(
SPLIT(
FILTER(A2:A&"♦♥"&B2:B,A2:A<>"")&",",
"♥"
),
"SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1",0
),,10^7
)
),
"♦"
),
"^(?:,?\s*)+|(?:,\s*)$|(,)\s*(?:,\s*)*","$1"
)
)
Use this formula-
={UNIQUE(A2:INDEX(A2:A,COUNTA(A2:A))),BYROW(UNIQUE(A2:INDEX(A2:A,COUNTA(A2:A))),LAMBDA(x,JOIN(",",FILTER(B2:B,A2:A=x))))}
Here A2:INDEX(A2:A,COUNTA(A2:A)) will return a array of values as well cell reference from A2 to last non empty cell in column A (Assume you do not have any blank rows inside data). If you have blank row, then you have to use different approach. See this post by #TheMaster
Then LAMBDA() will apply for each unique value return by INDEX() function to gather corresponded values from B column.
Inside lambda, JOIN() will concat those filtered values into one single string.
And finally, by {} results will be combined into on array for output.

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 COLUMN TOP ArrayFormula to calculate ROW wise which require ROW-wise ArrayFormula

Ref link below.
Essentially the aim to get a geometric progression with each term repeated X times.
The correct result on the sheet is obtained using an ArrayFormula across a row. This requires copying the formula column wise.
What I would like is a single ArrayFormula atop the column, that calcluates the results row wise (as indicated). My attempt on the sheet fails.
sheet link
New tab on your sample sheet called MK.Help. This formula is in cell E1.
It uses what I (and some others probably) call a query header smush. it takes advantage of query()'s built in ability to concatenate multiple header rows. It feeds a Transposed array into a query, then pretends like the whole thing is all header rows by setting the 3rd parameter of QUERY() equal to a very large number. It's common with this trick to use 9^9 or 9^99 which is just a very concise way of writing a very large number (9 to the 99th power).
=ARRAYFORMULA(
IF(
ROW(A:A) = 1,
"Result",
TRANSPOSE(
SUBSTITUTE(TRIM(
QUERY(TRANSPOSE(
REPT(
IF(
SEQUENCE(1,MAX(C:C),0) > C:C,,
ROUND(A:A * B:B ^ SEQUENCE(1,MAX(C:C),0)) & CHAR(10)
),
D:D
)
),, 9^9)
), CHAR(10), ",")
)
)
)
Same solution as Matt's, the only difference is that repetition is done using regex.
Try this (on sheet kishkin):
=ARRAYFORMULA(
IF(
A2:A = "",,
REGEXREPLACE(
REGEXREPLACE(
TRANSPOSE(QUERY(TRANSPOSE(
IF(
SEQUENCE(1, MAX(C2:C)) > C2:C,,
ROUND(A2:A * B2:B ^ SEQUENCE(1, MAX(C2:C),)) & ","
)
),, MAX(C2:C))),
"[^,\s]+,?",
REPT("$0", D2:D)
),
"\s+|,\s*$",
)
)
)

search for a specific Column and then lookup the value of the matching row based off a name

I am trying to get a google sheet to search for a specific cell in a table. The headers change so it might be A6 one week and then A9 the other and so on.
Once it's found that row, I want it to search and pull all of that departments names and data for the column its matched with.
I am 23 sheets in and my heads hit a brick wall and I just can figure it out.
You can try:
=QUERY({A:B,INDEX(A:G,0,MATCH(D25,1:1,0))},"SELECT * WHERE Col2='" & LOWER(F25) & "'")
Note - you should remove unnecessary spaces. In sample data, they were in cells C1 and D25.
Try this:
=QUERY(
FILTER(
IFS(
TRIM(1:20) = "", 0,
ISNUMBER(1:20), 1:20,
True, LOWER(TRIM(1:20))
),
1:1 <> ""
),
"SELECT Col1, Col2, Col" & MATCH(TRIM(D25), ARRAYFORMULA(TRIM(1:1)),) & "
WHERE Col2 = '" & LOWER(F25) & "'",
1
)
You can use a combination of CHAR(MATCH...)) and Query formula to get this
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, "&CHAR(MATCH("Log 4",'Sheet Name'!A1:G1)+64)&" WHERE B='w'")
Above formula only works till column Z, but thanks to Kishkin's comment below, you can use it beyond Z like this:
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, `" & =REGEXEXTRACT(ADDRESS(1, MATCH("Log 4",'Sheet Name'!A1:G1), 4), "\D+") & "` WHERE B='w'")
You use SUBSTITUTE instead of REGEXTRACT too. You can refer to this Question.
the CHAR(MATCH...)) gets the column name of the desired Log
you can then use the column name to include that column in Query select statement
In the MATCH formula, you can also dynamically Match for a cell reference instead of specifying "Log 4" manually
Note: This is basically splitting the Query formula and concatenating it with another formula. So the &, ' and " symbols are really important
Sample Screenshot:

Sheets - Lookup using 3 criteria including variable

Struggling with arrayFormula and vlookup with match to reference data in another sheet tab to pull a percentage based on row and column membership.
I currently have: =ArrayFormula(vlookup(Orange&7,{A1:A&B1:B,C1:E},match("Skill 3",A1:E1,0)-1,0))
In the shared Google sheet, I have placed notes and explanations. This is a reference sheet for a game, where it refers to Hero skills statistics.
MISSION: Using inputted Hero Class "colour" and "Skill Level" get the "percentage" from the appropriate skill column. This will be needed 3 times to cater for the 3 different skill types in question.
Here is the sheet: TEST Sheet
Approach
Creating a VLOOKUP using more than one criteria will require a helper column made by the concatenation of the two(or more) criteria.
In your case you should build a column that concatenates the Color & Level. Your Lookup will search that value and return the corresponding percentage in the 4th column.
Having your table in Hero Lead like this:
+==========================================+
| A | B | C | D | E | F |
+------+-----+-----+-------+-------+-------+
|Lookup|Class|Level|Skill 3|Skill 4|Skill 7|
+------------------------------------------+
You can use this formula to retrieve the correct value of Skill 3
=VLOOKUP("Orange"&7,'Hero Lead'!A:D,4,0)
Just replicate the formula with the other parameter to retrieve the correct percentage level.
Here is a solution:
=IFERROR(
INDEX(
QUERY(
'Hero Lead'!$A$2:$E,
"select C, D, E
where A = '" & $C$36 & "' and
B = " & G36,
-1
),
0,
MATCH(
"Skill " & F36,
'Hero Lead'!$C$1:$E$1,
0
)
),
0
)
This gets you the right skill's boost from the row filtered using QUERY by level and colour.
If you need all three at once for fixed colour and fixed level (in a column thus TRANSPOSE):
=TRANSPOSE(
FILTER(
'Hero Lead'!$C$2:$E,
'Hero Lead'!$A$2:$A = $C$36,
'Hero Lead'!$B$2:$B = G36
)
)
or:
=TRANSPOSE(
QUERY(
'Hero Lead'!$A$2:$E,
"select C, D, E
where A = '" & $C$36 & "' and
B = " & G36,
-1
)
)

Resources