ARRAYFORMULA repeating results of VLOOKUP - google-sheets

I've been forced to change a formula in my spreadsheet and can't seem to get the ARRAYFORMULA to fill down the column without repeating the same result.
Here is the code that works in a single row:
=ArrayFormula(SPLIT(CONCATENATE(QUERY(coreAbilities!$A$2:$E,"SELECT B,C,D,E where A = '"&VLOOKUP(C2:C,unitData!$C$2:$D,2,)&"'",0)&":"),":"))
​I've tried wrapping it in a VLOOKUP, but nothing seems to get the job done.
Basically, I'm searching a table of 5 columns and finding a match to a name, however, the name is not the same between these two tables. The name I'm searching has to first be matched to it's "code name" in another table and then I can search the final table. On top of that, each name has 3-5 matches, each with 5 values. So simply using a VLOOKUP doesn't seem to do the trick.
I've tried VLOOKUP and FILTER in hopes of making this easier on myself, but the only formula I can manage to get the results I need (at least in the proper order) is by using QUERY.
I'm not married to the method I'm using, but it's gotten me this far, so I've just been trying to force it through.
Here's my sheet
Heros!H2

QUERY does not support arrays/ranges inside itself under string parameters.
the only possible way is to use regex capabilities within QUERY like:
however TEXTJOIN belongs to a group of formulae that are limited to 50000 character input, eg. this won't work with your massive arrays. therefore double VLOOKUP is your friend. but as you noticed VLOOKUP can output always only the first found result and every next finds will be just a clones/repeats of the first match.
so the trick is to append a counter to the vlooked up value which will force new finds instead of cloning previous finds:
=ARRAYFORMULA(IFERROR(VLOOKUP(COUNTIFS(IFERROR(VLOOKUP(C2:C, unitData!$C$2:$D, 2, 0)),
IFERROR(VLOOKUP(C2:C, unitData!$C$2:$D, 2, 0)), ROW(M2:M), "<="&ROW(M2:M))&
IFERROR(VLOOKUP(C2:C, unitData!$C$2:$D, 2, 0)),
{COUNTIFS(coreAbilities!A2:A, coreAbilities!A2:A, ROW(coreAbilities!A2:A), "<="&
ROW(coreAbilities!A2:A))&coreAbilities!A2:A, coreAbilities!B2:E}, {2,3,4,5}, 0)))
UPDATE:
=ARRAYFORMULA(TRANSPOSE(QUERY(TRANSPOSE(IFERROR(SPLIT(IFERROR(VLOOKUP(
IFERROR(VLOOKUP(C2:C, unitData!$C$2:$D, 2, 0)),
SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(QUERY({coreAbilities!A2:A&"♦",
"♠"&coreAbilities!B2:B&"♠"&coreAbilities!C2:C&"♠"&coreAbilities!D2:D&"♠"&coreAbilities!E2:E,
coreAbilities!C2:C}, "select Col1,max(Col2) group by Col1 pivot Col3", 0),
"offset 1", 0)),,999^99)), "♦"), 2, 0)), "♠"))), "offset 1", 0)))

Related

How do I find a row, find the highest value in that row, and return that column header?

In the below spreadsheet, I am trying to find the bar with the highest sales per show. So I want the formula in cell B2 on the 'FRONT SHEET' to look at the 'BAR SALES' sheet and find the specific show, find the highest sales in that row, and then pull the bar name.
I am currently using this formula which works; however, the formula is specific to this show. I want the formula to be broader and be able to search for the show in the 'BAR SALES' sheet.
=INDEX('BAR SALES'!$B$1:$F$1,MATCH(MAX('BAR SALES'!B2:F2,'BAR SALES'!B2:F2),'BAR SALES'!B2:F2,0))
This is a dummy spreadsheet but has the gist. My actual sheet is a lot bigger so I want to be able to search a long list of shows for this information without specifically tailoring the formula to each show in that list. Can I add a vlookup in this formula somehow??
[https://docs.google.com/spreadsheets/d/1dcjjQyZj9ANUTyTMloiY2CX94nBSYLt5hCiSWzY3tBk/edit#gid=1376876918][1]
use:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, SORTN(SORT(SPLIT(
FLATTEN('BAR SALES'!A2:A&"×"&'BAR SALES'!B1:F1&"×"&'BAR SALES'!B2:F),
"×"), 3, 0), 9^9, 2, 1, 1), 2, 0)))
This is a slightly longer version of #player0's. Either will return the same response. They both do a FLATTEN and then a SPLIT to generate three columns. Test each out with your data to see if either is faster. They should be roughly the same, but its worth testing.
=ARRAYFORMULA(
IF(ISBLANK(A2:A),,
IFERROR(
VLOOKUP(
A2:A,
QUERY(
SPLIT(
FLATTEN(
IF(ISBLANK('BAR SALES'!A2:A),,
'BAR SALES'!A2:A&"|"&'BAR SALES'!B1:F1&"|"&'BAR SALES'!B2:F)),
"|"),
"where Col3 is not null
order by Col3 desc"),
2,FALSE))))

Google Sheets Column function to get Average of all the columns in a range to the right using current row

I'm not sure why I can't find examples of this.
But I want my column E to have an average of all the columns to the right. In single example it's:
=AVERAGE(F2:O2)
Now I try to do this for the whole column:
=ArrayFormula(IF(ROW(E:E)=1,"Aggregate",AVERAGE(F:O)))
The problem is it doesn't do it per row, it just does the whole array. Maybe i don't want to use ArrayFormula
I should also put a IF(ISBLANK(F (Row())), "" So I don't calculate blank rows.
How do I put dynamic row on this?
try:
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(F2:O),
"select "&TEXTJOIN(",", 1,
IF(TRIM(TRANSPOSE(QUERY(TRANSPOSE(F2:O),,99^99)))<>"",
"avg(Col"&ROW(F2:F)-ROW(F2)+1&")", ))&"")),
"select Col2"))

Google Sheets ArrayFormula Sort & Split Issue

Have been researching several places for a solution and found something that quasi works but doesn't work in the ArrayFormula for Sheets. I have data in a single column as an example below. It's a combination of letters and text but would otherwise been sortable when parsed. The goal is to populate the cell with the single most recent event (as measured by the highest number at the end of the string). The value "Sprint" is consistent text. This formula seems to work for that purpose, however, I would ideally like this to work within the ArrayFormula so that it would adjust and populate with the data rows it's referencing which is dynamic. Thanks in advance.
TRIM(CHOOSE(1,SPLIT(JOIN(";",SORT(TRANSPOSE(SPLIT([#CELL],";",FALSE)),1,FALSE)),";")))
Below is a sample set of data:
Sprint 1
Sprint 2
Sprint 3
Sprint 3;Sprint 1
Sprint 1;Sprint 2
try:
=ARRAYFORMULA(B1&" "&QUERY(TRANSPOSE(QUERY(TRANSPOSE(
REGEXREPLACE(IFERROR(SPLIT(B2:B, ";")), "\D+", )*1),
"select "&TEXTJOIN(",", 1, IF(B2:B<>"",
"max(Col"&ROW(B2:B)-ROW(B2)+1&")", ))&"")),
"select Col2"))
UPDATE:
=ARRAYFORMULA(IF(REGEXMATCH(B2:B, B1),
B1&" "&QUERY(TRANSPOSE(QUERY(TRANSPOSE(
REGEXREPLACE(IFERROR(SPLIT(B2:B, ";")), "\D+", )*1),
"select "&TEXTJOIN(",", 1,
"max(Col"&ROW(B2:B)-ROW(B2)+1&")")&"")),
"select Col2"), ))

How to use Averageifs or Sumifs in an Arrayformula

I'll post a link to the spreadsheet at the bottom of this write-up.
I'm trying to work out the average of a column of numbers that fall between a date range. The formula below works but I have to drag it down the column, I want it to be an array so it auto updates.
=iferror(averageifs(B$2:B,A$2:A,">="&C2,A$2:A,"<="&D2),1)
So I created it as an array as follows:
=iferror(ArrayFormula(averageifs(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1
But it stops after the first cell. So I broke up the average function into sum & count in order to divide.
The count array works using this formula:
=iferror(ArrayFormula(countifs(A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1)
However the sum array does not even go past the first cell:
=iferror(ArrayFormula(SUMIFS(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1)
And the combination gets past the first cell but the calculations all come to zero:
=ArrayFormula(iferror(SUMIFS(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)/countifs(A$2:A,">="&C2:C,A$2:A,"<="&D2:D),1))
What I'm trying to achieve is an average for the previous month.
If anyone can help me I'd be very grateful!
https://docs.google.com/spreadsheets/d/1XhoLl5hB-MpXFz9VS2aLqJOWbXk1d_7apnwKWFdDUlg/edit?usp=sharing
you are trying to apply a bit weird structural logic with lots of repeating values with no reason. basically, it looks like you need this:
=ARRAYFORMULA(QUERY({TEXT(A2:A, "yyyy-mmm"), B2:B},
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
order by avg(Col2) desc
label avg(Col2)''", 0))
but if you really really need so:
=ARRAYFORMULA(IF(LEN(A2:A),
IFERROR(VLOOKUP(TEXT(DATE(YEAR(A2:A), MONTH(A2:A)-1, 1), "yyyy-mmm"),
QUERY({TEXT(A2:A, "yyyy-mmm"), B2:B},
"select Col1,avg(Col2)
where Col2 is not null
group by Col1", 0), 2, 0), 0), ))

Is there a reason why my ArrayFormula is not working in the other cells of my column?

In a Google sheet with form responses, I made an additional column where I want to look up from each submission if the value left of my new column already occurs in a range on another sheet.
So this is going to be a Vlookup formula finally.
Unfortunately, I didn't make it to the Vlookup part yet because the ArrayFormula part is not working.
I started off by looking to the cell value at the left with this formula, which worked, but the ArrayFormula part of it DOESN'T work.
=ArrayFormula(indirect(ADDRESS(ROW(), COLUMN()-1)))
I know that some functions don't work very well with ArrayFormula,
But I don't see any reason here this should not work because it's only looking to its row and its column.
I hope the image shows the problem well enough
If you just want to repeat the values from the previous column (let's say column A, starting in row 2), you can try in column B (also in row 2)
=Arrayformula(if(len(A2:A), A2:A,))
Change range to suit. See if that helps?
UPDATE: To repeat the previous column (anywhere you input the formula) try (in row 2)
=offset(A1, 1, column()-2, rows(A1:A))
To 'limit' the output you can use any number instead of rows(A1:A) or replace it with COUNTA(A1:A)...
you can do something like this, which will search for specific header across entire sheet and then return values of that column:
=QUERY({INDIRECT("Sheet1!"&
ADDRESS(1, MATCH("job ID", Sheet1!1:1, 0), 4)&":"&
ADDRESS(1000000, MATCH("job ID", Sheet1!1:1, 0), 4))},
"select * where not Col1 matches 'job ID' and Col1 is not NULL", 0)
without sheet name:
=QUERY({INDIRECT(
ADDRESS(1, MATCH("job ID", 1:1, 0), 4)&":"&
ADDRESS(1000000, MATCH("job ID", 1:1, 0), 4))},
"select * where not Col1 matches 'job ID' and Col1 is not NULL", 0)

Resources