Trouble with ARRAYFORMULA for auto-filling formulas in Google Sheets - arrays

I'm attempting to automatically populate a Google Sheets column in a "Results" sheet with the following formula, which draws data from a "Source" spreadsheet:
=IFERROR(INDEX(Source!$B$2:$D,MATCH($A2&C$1,Source!$B$2:$B&Source!$C$2:$C,0),3)," ")
When I place that formula in ARRAYFORMULA, it does not auto-populate, and changing the MATCH search_key to a range (i.e., $A2:$A&C$1) does not fix the problem.
I.e., neither of these work:
=ArrayFormula(IFERROR(INDEX(Source!$B$2:$D,MATCH($A2&C$1,Source!$B$2:$B&Source!$C$2:$C,0),3)," "))
=ArrayFormula(IFERROR(INDEX(Source!$B$2:$D,MATCH($A2:$A&C$1,Source!$B$2:$B&Source!$C$2:$C,0),3)," "))
Is there a way to fix this? Or an alternative way to automatically fill a formula? I'm also open to using a function other than INDEX/MATCH, so long as it can do a lookup based on two vertical criteria. Unfortunately I don't think a pivot table would suit my purposes, since my "Results" page also queries another spreadsheet to provide other information.
Example here: https://docs.google.com/spreadsheets/d/1dsaMYsJeZl2o_rNTLwaVhnEehFvAKRMXghAJeEK220s/edit?usp=sharing

This is the formula you are looking for:
=ARRAYFORMULA(IFERROR(HLOOKUP(Source!$D$2,Source!$D$2:$D$11,MATCH($A2:$A4&C$1,ARRAYFORMULA(Source!$B$2:$B&Source!$C$2:$C),0),0),0))
I tested this and it works perfectly fine.
TL;DR
To answer why your formula is wrong,
The second argument in MATCH should have an ARRAYFORMULA otherwise you are basically matching only with first element.
INDEX doesn't work with ARRAYFORMULA. It can only search for a single value in a given range.
The first part can be solved by adding ARRAYFORMULA inside MATCH.
A simple VLOOKUPcould have solved the second problem if you weren't searching for a combination of cells (Date and Name). A twisted HLOOKUP comes to your rescue.
Without the IFERROR part, the formula looks like this:
=ARRAYFORMULA(HLOOKUP(Source!$D$2,Source!$D$2:$D$11,MATCH($A2:$A4&C$1,ARRAYFORMULA(Source!$B$2:$B&Source!$C$2:$C),0),0))

This formula produces the same output (see cell I1):
=QUERY({Source!A:D,ARRAYFORMULA(VLOOKUP(Source!B:B,'Project Lookup'!A:B,2,0))},"select Col2,Col5,sum(Col4) where Col1 is not null group by Col2,Col5 pivot Col3")

Related

Google Sheets: Using Transpose on an array in other tabs & identifying the tab by

I would appreciate some help, please.
I have a google sheet with many tabs with data going horizontally.
I would like to create a formula that imports and transposes the data into a vertical list.
However, I want to be able to type in (or drop-down list) to select the tab which the transpose formula to look at. I cannot get anything to work. I have tried this
=TRANSPOSE(A1&!B2:J2)
To add to that if it could use a lookup (vlookup or hlookup) to find the correct row to transpose then that would be great also.
I have set up a test sheet below. Please help. Many Thanks Tim https://docs.google.com/spreadsheets/d/1Menn6Z1mLl8wYOrcdQFnfs7Lp0dbC9UJe1S3AQRcOS0/edit#gid=0
You should not use IMPORTRANGE to work with data that exists anywhere in the same spreadsheet. IMPORTRANGE is for use retrieving data from a separate spreadsheet.
Instead, delete your current Sheet1!A2 formula and replace it with this:
=ArrayFormula(TRANSPOSE(INDIRECT(A1&"!B16:J16")))
I also added a new sheet ("Erik Help") with an advanced formula that accomplishes your lookup using whatever is types in B1. If whatever is typed in B1 exists in Column A of the selected sheet, the results of that row will be retrieved. If no match is found, IFERROR will return "No Match Found."
That formula, in 'Erik Help'!A2:
=ArrayFormula(IFERROR(QUERY(TRANSPOSE(INDIRECT(A1&"!B"&VLOOKUP("*"&B1&"*",{INDIRECT(A1&"!A:A"),ROW(INDIRECT(A1&"!A:A"))},2,FALSE)&":"&VLOOKUP("*"&B1&"*",{INDIRECT(A1&"!A:A"),ROW(INDIRECT(A1&"!A:A"))},2,FALSE))),"Select * WHERE Col1 Is Not Null"),"No Match Found"))

How do I get value of an indirect formula into a format that can go into an array?

My Google Sheet that will be updated over time with new sheets. On my dashboard/master sheet, I can write a simple INDIRECT that will pull information from a cell in the sheets. However, the formula does not replicate its way down the column. I understand that I need to use an ARRAYFORMULA to get the auto formula placement done.
I've tried many ways but the one that I think may get me there is to use CONCAT. My columns look like this:
Event Title [uses a script to pull in the names of all the sheets]
Use an array to get the titles so they pre-poluate down the column so I can use it later: =ARRAYFORMULA(IF(Row(A:A)=1,"Get Title from A",IF(ISBLANK(A:A),"",A:A)))
-- The Event Title is now appearing as plain text in Column B.
I then use CONCAT to write the part of the formula I need to help get the name of the INDIRECT in without using the INDIRECT formula.
=CONCAT("'"&B5&"'"&CHAR(38)&"!"&"""","B2"&"""")
-- This gets me this result: 'Computers 101'&"B2"
At this point, my hope is that I could then use this information ('Computers 101'&"B2") into an ARRAYFORMULA. I used this formula to try and do that:
={"Event Date";ARRAYFORMULA(A6:A+D6:D&"Cat")}
-- I get the answer: 0
The expected value was the date cell (B2) in the Computers 101 sheet. Any ideas how to proceed? I don't know the names of the sheets in advance.
unfortunately, this is not possible within of scope of google sheets formula. if you need ranges from other than the actual sheet you need to use INDIRECT which is not supported under ARRAYFORMULA.
you have 3 options:
hardcode it like: https://stackoverflow.com/a/68446758/5632629 with IFERROR & array of empty cells to match columns of your range
generate formula which will generate your final formula/range as a text string and then use a simple script to convert that string into the valid formula: https://stackoverflow.com/a/61819704/5632629
do it all with scripts

Find and repeat a cell value if values match

My spreadsheet is collecting data from a form
On another tab I'm showing the responses that match "Lesson day" with "Today's date" (in the example, all the lessons are showed).
As you can see, the "e-mail" field is filled out only once.
Is there a way to automatically fill the "e-mail" field in the second tab? Maybe matching the "Student Code" with the "e-mail" fields in the first tab?
I've tried the MATCH() function but it returns only the position. I feel like I need to combine MATCH() with other functions but I have no idea about where to start
EDIT: Having the email adresses on another column would work too.
SOmething like: if the "Student Code" in the 2 tabs matches, show the email adress for that "Student code"
try:
=ARRAYFORMULA(IFNA(VLOOKUP(D4:D, FILTER({form!E2:E, form!G2:G}, form!G2:G<>""), 2, 0)))
change form to match the sheet name of your form sheet
As suggested, I created an auxiliary table (just called Sheet7) and getting closer to the desired result
In A column I used
=UNIQUE(Lessons!E:E)
In column B I used
=INDEX(Lessons!A:M, MATCH(A2,Lessons!E:E,0),7)
Then, on my second spreadsheet, I could get all the e-mail adress using the following formula
=INDEX(Sheet7!A:B, MATCH(D4,Sheet7!A:A,0),2)
I've tried to use ArrayFormula on the auxiliary table
ARRAYFORMULA(if(A2:A="",,INDEX(Lessons!A:M, MATCH(A2:A,Lessons!E:E,0),7)))
But it doesn't work. It shows only the email adress matched from the cell A2, ignoring A3, A4,...
A different approach:
Make an extra column in your form responses sheet called "Student E-mail".(In this example it is column "I")
In row 2 of that column, write the following formula:
=ARRAYFORMULA(IF(ISBLANK(G2:G),VLOOKUP(F2:F,INDIRECT("F$2:G"&ROW(I2:I),TRUE),2),G2:G))
Use that column for the emails in your other tab (hide the original email column)
Update:
Using array formula, you don't have to manually drag & drop. And it keeps going as new rows are added.
Usually MATCH is combined with INDEX
You should build an auxiliary table with one column for names and another for ee-mails.
To build the auxiliary table from the collected data you could use something like this
=UNIQUE(FILTER({Lessons!E:E,Lessons!G:G},LEN(Lessons!G:G)))
The above is better than using a formula for each column as this prevent having mismatching data.
INDEX / MATCH usually doesn't return the "expected" results in an ARRAYFORMULA. Instead use VLOOKUP.
NOTES:
Please bear in mind that every time that you edit a value the formula will be recalculated. If you have a lot of formulas (like when doing a fill down to copy a formula to all the cells in a column) or having an ARRAYFORMULA with open ended references i.e. G2:G this could affect your spreadsheet performance.
If you go for using an ARRAYFORMULA, use ARRAY_CONSTRAIN to limit the number of rows returned by your formula.
Related
How to map values between columns in worksheets

Use array formula with index match

Is it possible to do an array formula with index match:
e.g:
=arrayformula(if(len(A3:A),INDEX('SheetB'!E:E,MATCH(A3:A,'SheetB'!H:H,0))))
If not, is there a solution that doesn't involve google scripts?
It seems INDEX can not return multiple values. It can not be used inside ARRAYFORMULA.
The only solution I know of is to use VLOOKUP.
See this thread :
https://productforums.google.com/forum/#!topic/docs/jVvjbz8u7A8
Example from there :
=ArrayFormula(VLOOKUP( B12:B15; H2:R32; 1; TRUE))
Cheers!
Use XLOOKUP
=ARRAYFORMULA(XLOOKUP(K2:K,R2:R,S2:S))
With XLOOKUP you can look in one column for a search term, and return a result from the same row in another column, regardless of which side the return column is on
In the OP's specific case, one can actually use VLOOKUP for its intended purpose, as a replacement for MATCH:
=arrayformula(if(len(A3:A),VLOOKUP(A3:A,{SheetB!E:E,SheetB!H:H},2,false)))
In the general case of trying to use INDEX to retrieve multiple values, it can be replaced with a kludge of VLOOKUP and SEQUENCE:
=arrayformula(VLOOKUP(A:A,{SEQUENCE(rows(B:B)),B:B},2,true))
does what would have been accomplished by
=arrayformula(INDEX(B:B,A:A))
if the latter worked as OP expected.
I know this is old now, but it turns out that INDEX() acts as a defacto ARRAYFORMULA() now. You can see a fabulous example of this on this google sheet, which shows how to use a and index(split()) to extract a particular set of text from a cell. The MK.demo tab provides a visual on how the array formula is implied with the INDEX() function.
Nowadays, using a FILTER() or QUERY() function can give the kinds of multiple vlookup the OP was looking for.
im not sure if its gonna work but i did an "IF(ISBLANK() before the INDEX(...) in the ARRAYFORMULA and it went down all the way

Create array with vlookup

I want to conditionally grab lines from a database-style spreadsheet in Google Spreadsheets (a list with a name, location, description, price) after checking the value with a vlookup - I've used this a while ago and expected it to CONTINUE an array across for the other columns next to the one 'looked up', but it seems my memory fails me here and it just retrieves the 'searched out' value.
=vlookup("Yes",'All 2014-15'!A2:G,2)
This formula basically finds the first value of the desired rows and should create a 'Selected items from 2014-15' list, but I can't work out how to expand it to produce a list of all the rows I want. Is there a simple way to retrieve this, I've tried playing with arrayformula but no success.
I can change the index simply to get the other values across, but if this could be filled out through an array too that would be preferable...?
Can you try this...
=FILTER('All 2014-15'!A2:G,'All 2014-15'!A2:A="Yes")
Edit:
As suggested by Immx, added apostrophes to sheet name and the second range changed to A2:G to A2:A assuming the yes/no data is in A column.

Resources