Can de search key of MATCH be a row of values? - google-sheets

I am would like to use the values in the name column (search key) and look them up in a table with the headers [name, regular, overtime].
The formula I am using is:
=ArrayFormula(index(rateTable, match(formName,workers,0),match(formType,rateTypes,0),0)*{formHours})
It works except the search key in the MATCH formula, does not reference every respective entry in the name column, but only works with one fixed reference to a cell.
Am I trying to use this formula beyond its capabilities? I'd like to know if I should stop searching. Thanks.
Here is a link to a copy of my sheet:
https://docs.google.com/spreadsheets/d/1sovuTB4zSTpl0RUHciYltr-pf8g4KPTgkYVE5lB4Ifk/edit?usp=sharing
=ArrayFormula(index(rateTable, match(formName,workers,0),match(formType,rateTypes,0),0)*{formHours})

for this task is best if you use VLOOKUP formula. paste in I2 cell:
=ARRAYFORMULA(IF(LEN(formName), IFERROR(VLOOKUP(formName, rateTable,
IFS(formType="Regular", 2,
formType="Overtime", 3), 0)) * formHours, ))
demo spreadsheet

INDEX doesn't work with arrays as needed for ARRAYFORMULA. Either…
use copied formulas rather than a single ARRAYFORMULA, e.g.
=IF(NOT(LEN(A2)),"",index(rateTable, match(C2,workers,0),match(G2,rateTypes,0))*H2)
and drag-copy it down column I,
or refactor your INDEX(,MATCH( use to rely instead on VLOOKUPs and HLOOKUPs.

Related

Array formula is not working with the combination of Vlookup and Indirect-Match?

I am trying to generate an arrayformula for the whole column but it does not work, when I use the same formula cell by cell, it generates correct value. Here is the formula for F1 cell:
=if(Iferror(vlookup($D1, INDIRECT("$"&"A"&MATCH(E1,$B:$B,0)+1&":$B"),2,false),"")=E1,"",Iferror(vlookup($D1, INDIRECT("$"&"A"&MATCH(E1,$B:$B,0)+1&":$B"),2,false),""))
I am trying to convert it into ArrayFormula like this and put it in F1:
=ARRAYFORMULA(if(Iferror(vlookup($D:$D, INDIRECT("$"&"A"&MATCH($E:$E,$B:$B,0)+1&":$B"),2,false),"")=$E:$E,"",Iferror(vlookup($D:$D, INDIRECT("$"&"A"&MATCH($E:$E,$B:$B,0)+1&":$B"),2,false),"")))
But this does not work and returns empty column, here is the sheet if you want to test it, you can find formula in column F:
https://docs.google.com/spreadsheets/d/13XLZvvdzK_mqr4Ous50cIEfernw2XrPJWvVgt1hFxtk/edit?usp=sharing
Please share your knowledge how to go about it as I am trying to learn formulas starting from basic level? Thank you.
when working with more than one condition, you can usually use FILTER for it. In this case, I used MAP to refer to both columns D and E, and used FILTER to narrow to the matches in A column, and then to those values that were further than the row of the MATCH of E value. Then, with INDEX I chose the first value of that resulting range.
=MAP(D:D,E:E,LAMBDA(d,e,IFERROR(IF(d="","",INDEX(FILTER(B:B,A:A=d,ROW(B:B)>MATCH(e,B:B,0)),1)))))
Unclear of the full scope but from your expected result scenario(in Column F) you seem to be pulling off second match(if any). well in that case try:
=BYROW(D:D,LAMBDA(dx,IF(dx="",,IFNA(FILTER(ARRAY_CONSTRAIN(FILTER(B:B,A:A=dx),2,1),{0;1})))))

Adding values based on other values but SUMIF is quite right

Here is a link to my spreadsheet. Essentially what I am looking for is if the task matches then I want to also be able to give a Tech level then from there add up the values. I put a note in the sheet but basically if I give a task value and a tech level I want the corresponding value but whenever I try to do multicolumn adding in my sumif it just gives me the value from the first column.
An example of the formula I want is something like =SUMIF(Name, Name2 and Rank, Add Values).
try:
=INDEX(IFNA(VLOOKUP(K3:K&"♥"&L3:L, SPLIT(FLATTEN(
IF(B2:D="",,A2:A&"♥"&B1:D1&"×"&B2:D)), "×"), 2, 0)))
I think what you are looking for can be done by using a Index-Match function.
e.g. If you paste the following formula in an empty cell somewhere in the sheet,
=INDEX($A$1:$D$8, MATCH("Task 1",$A$1:$A$8,0),MATCH("Tech 2",$A$1:$D$1,0))
it gives you 20 corresponding to Task 1 and Tech 2.
If you paste the following in an empty cell somewhere in sheet,
=INDEX($A$1:$D$8, MATCH("Task 7",$A$1:$A$8,0),MATCH("Tech 3",$A$1:$D$1,0))
it gives you 36 corresponding to Task 7 and Tech 3.

Fetching data from other Spreadsheet by comparing some values

I have a sample Spreadsheet such as
And I want to import data from this spreadsheet to another spreadsheet, but after comparing some data, such as
My noob formula for the selected cell name in the second image:
=Query(ImportRange("URL of first spreadsheet","sheet!B:D"),"Select Col2 where Col2=A.....(what to add here? this column 'A' is not working for comparing the names)
My Approach:
I will compare the values from the import range with the existing column i.e. previousSpreadsheet.name.A=thisSpreadsheet.this_name.A and compare every name and SELECT values accordingly for the next three columns (in yellow). I hope I'm clear.
What should I add here? Is my approach right? If not, What are the alternatives to achieve this?
Thanks.
EDIT
(following OP's request)
Also, can I compare two cols with one? such as where LOWER(Col2)='"&LOWER(A2)&"' or '"&F2&"' or Col2=A2 || F2 something like this? for comparing two cols with one?
If you start using more than one names as variables, you may want to consider using other alternatives for the where clause, like matches
=Query(ImportRange("URL of first spreadsheet","sheet!B:D"),
"Select Col2 where Lower(Col2) matches'"&LOWER({A2&"|"&F2})&"'")
Original answer
Please use
=Query(ImportRange("URL of first spreadsheet","sheet!B:D"),"Select Col2 where Col2='"&A2&"'")
(where A2 is the name you need)
Pay notice to the syntax referring the cell: single quotes ' double quotes" ampersand & cell A2 and again &"'.
No spaces in between
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, IMPORTRANGE("ID", "sheet!B:D"), {1,2,3}, 0)))

How to use absolute references in google sheets query formula or query by column names for multiple sheets?

I have the following problem. I'm trying to write query formula in order to put all values in one sheet by typing yes in one column, however, I have the following problem. Whenever I add a new column, references in query formula (multiple sheets) are changing and the formula doesn't work. How can I prevent this?
Or is there any way to query by a column name in multiple sheets?
I have tried locking relative references by putting sign $
I have tried to use an indirect formula to take references (data set in Helper TAB, cell E2) - nothing worked
I'm out of the ideas, for now, anyone knows how to fix this?
=QUERY({'Sheet 1'!$A:$Z;'Sheet 2'!$A:$Z;'Sheet 3'!$A:$Z;'Sheet 4'!$A:$Z}, "select * where Col1 ='yes'",0)
Here is the file I did, you can see query formula in Master sheet:
https://docs.google.com/spreadsheets/d/1XD-CECy5W5-HM5EkBFJQKDtLlykQq8Cj8ZOvDUXkd1s/edit?usp=sharing
A solution to the problem is to use a formula that searches for the column address based on a reference.
=SUBSTITUTE(ADDRESS(1;COLUMN(A1);4);"1";"")
This formula will return the value A, which is the column of address A1.
It can be used in query functions like this:
=QUERY(A:D;"SELECT "&SUBSTITUTE(ADDRESS(1;COLUMN(A1);4);"1";"")&"")
This function is equivalent to the function:
=QUERY(A:D;"SELECT A")

How to definitely use column names in Google Sheet Query

query function doesn't let you use column names; you have instead to use letters if you refer to a cell range or ColN if you refer to an array.
This is very annoying, most of all when you alter the queried table adding, deleting or exchanging columns.
I would like to use column names, like in a standard SQL query.
You can actually get around this by splitting the Query formula and using other formula's to automatically get the desired column names from a list.
For example if you have a table in range A1:E15 with headers "H1, H2, H3, H4, H5", and you'd like to only get columns H3 & H5:
Store the desired headers (H3 & H5) in another table/range as a list - lets say this range is G1:G2
Use MATCH formula along with TextJoin formula to generate an concatenated string like Col3, Col5
=TextJoin(", ",TRUE,ArrayFormula(IFERROR("Col"&MATCH(G1:G6,$A$1:$E$1,0),"")))
Lets say this was in cell H1
You can refer to this cell in your Query formula like below
=QUERY({A1:E20},"SELECT "&H1&" WHERE Col2='w'")
You can see it in action in below screenshot:
One solution could be recurring to some custom function created by a script, but when you have a not so small table you surely will incur in some error due to the exceeding computation time.
The most efficient solution (using only native functions) I found is as follows.
Suppose you are working on a sheet range, your column names are in row 1 and you want to refer to the column "salary"; you can obtain the column letter by
substitute(address(1,match("salary",A1:1,0),4),"1","")
Instead, if you are querying arrays, it is simpler; the string you need is
"Col"&match("salary",A1:1,0)
The final query could be not so elegant, but the efficiency is guaranteed:
query(
employeessheet!A:E,
"select "&substitute(address(1,match("salary",employeessheet!A1:1,0),4),"1","")&" where ...",
1)

Resources