How to look up a value in multiple columns and then extract the corresponding relative value.
example: there are (100rows x 3columns) x 5 sets next to next with name, phone, email. so search for phone(unique), and return the corresponding name.
Vlookup performs only one column
match takes on one row or column
Sample sheet attached
Need values in the 2nd sheet
To perform multiple criteria in a VLOOKUP, the easiest way would be to create a helper column. For example, you can concatenate all the parameters you want to include as criteria with a character like the underscore _, and perform a VLOOKUP with the key also concatenated.
You can also do it without helper columns if you combine INDEX and MATCH. To do this, it's set up the same way as a single-criteria INDEX/MATCH, except the MATCH is set up to search for 1 as a key, with the lookup array being (condition_range1=condition1)*(condition_range2=condition2)*....
I've set up an example showing both techniques here: https://docs.google.com/spreadsheets/d/12viS6lkaokXs-G6Wl4UU7H6-wmNX_79XYm-JCPPSBdU
paste in Sheet2!C3 cell:
=ARRAYFORMULA(IFERROR(VLOOKUP(A3:A,
{Sheet1!B:H; Sheet1!I:O; Sheet1!P:V; Sheet1!W:AC; Sheet1!AD:AJ; Sheet1!AK:AQ},
{3, 4, 5, 7}, 0)))
Related
I have a spreadsheet with multiple columns. Each column represents a recipe. Each column has a week number (e.g. 2, 3, 4)... Below the week number, we have a variable number of ingredients. I want to be able to merge all the ingredients from a given week into a single column.
Sample Data
I know how to statically merge ranges e.g. {B4:B20;C4:C20} and I can also think of using an if statement to check the week value e.g. =if(B1=2,{B4:B20;C4:C20}) but that's not close to what I want. I need to check the range B1:Z1 for the value of the week and if that value is X (let's say 2) then take the ingredients in B2:B and tack them on to C2:C and so on...
If I'm understanding you correctly, this should do it:
=QUERY(FLATTEN(FILTER(B3:Z,B1:Z1=2)),"WHERE Col1 Is Not Null")
FILTER keeps (i.e., "filters in") only the data in B3:Z where the header is 2.
FLATTEN forms one column (blank cells and all) from the FILTER results.
QUERY keeps only non-blank (i.e., Is Not Null) entries from that single-column list.
I'm attempting to take a CONCATENATEd value in a column (A), SPLIT that value in two and VLOOKUP two columns in another sheet (same file). The issue I'm running into is if there are not two values to SPLIT in the CONCATENATEd cells, I get an error. I can flip my formula to search for two values or one (two values JOINed with : or a single value), but not both.
This is the latest iteration of my formula that's only showing half of the desired results.
=ArrayFormula(VLOOKUP(IF(FIND(":",A3:A),SPLIT(A3:A,":"),A3:A),{materialsData!C2:C,materialsData!D2:D,materialsData!E2:H},4,))
Here is an example sheet of what I'm trying to do.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A3:A, {IF(materialsData!D2:D<>"",
materialsData!C2:C&":"&materialsData!D2:D, materialsData!C2:C), materialsData!F2:F}, 2, 0)))
I've created a form to collect data from user A in a sheet and reformat it for user B in the other sheet.
I have to sort the data for user B. I'm using vlookup to sort the column of values from the form to a new sheet (sort based on the order of the 'value description column'). It's working.
My problem is that when a new column is added to the first sheet (the form) the column range is modified and the index parameter in vlookup is not good anymore. So I lost everything on my second sheet.
How can I do to have a solid link with the column in the first sheet even if it's position change?
you can make use of INDIRECT with COUNTA and SUBSTITUTE. something like:
=INDIRECT("Sheet1!A1:"&SUBSTITUTE(ADDRESS(1, COUNTA(Sheet1!1:1), 4), 1, "")
this will count non-empty cells in row 1 of Sheet1 and converts that number to later which is used in constructing the range put together by indirect formula and all of it can be placed in vlookup as same as you would place any ther regular range.
I am trying to setup a mapping of a list of values. One cell in a row contains a list of IDs or row numbers, and another cell in the same row contains a list of mapped values.
This is very simple with JOIN, ARRAYFORMULA and SPLIT if you are doing some basic math, for example:
A1: =1,2,3
A2: =JOIN(",",ArrayFormula(SPLIT(A1,",")+1))
A2: displays "2,3,4" (correct)
This does not seem to work robustly with LOOKUP and SPLIT (also tried LOOKUP and REGEXEXTRACT). Specifically, I can get it to work, even with variable parameters, but as soon as I change the rows the values break. Example:
A column: ids (e.g. 1,2,3,4)
C column: names (e.g. "Apple", "Banana", "Custard")
E7: =1,2,3
F7: =JOIN(",",ArrayFormula(LOOKUP(SPLIT($E7, ","), $A:$A, $C:$C)))
F7 displays "Apple,Banana,Custard" (correct)
The above is correct behaviour. However, if I drag row 1 (id 1) to a different place, the formula breaks.
F7 displays "#N/A Did not find value `1` in LOOKUP evaluation"
The behaviour is not specific to LOOKUP or SPLIT, as I have also tried it with VLOOKUP and REGEXEXTRACT (in fact, with REGEXEXTRACT it is more difficult to support variable list size).
Sample Sheet
SOLUTION
It works when using "=ROW()." The actual problem, as pointed out by AdamL, is that the is_sorted flag needs to be false (if you want to support drag & drop)
E7: =ROW(A2)&","&ROW(A3)&","&ROW(A4)
F7: =JOIN(",",ArrayFormula(VLOOKUP(SPLIT($E7, ","), $A:$C, 3, 0)))
F7 displays correct value even after dragging row 1
I think the issue is: when you drag and drop, the lookup list is no longer sorted, and LOOKUP, along with VLOOKUP without FALSE (or 0) specified for the (optional) fourth argument, requires a sorted list. So I think the solution is to use VLOOKUP, but with the fourth argument specified:
=ArrayFormula(JOIN(",",VLOOKUP(SPLIT($E5,","),$A:$D,3,0)))
I am trying to use the INDEX() formula inside an ARRAYFORMULA(). As a simple (non-sense) example, with 4 elements in column A, I expected that the following array formula entered in B1 would display all four elements from A in column B:
=ARRAYFORMULA(INDEX($A$1:$A$4,ROW($A$1:$A$4)))
However, this only fills field B1 with a the value found in A1.
When I enter
=ARRAYFORMULA(ROW($A$1:$A$4))
in B1, then I do see all numbers 1 to 4 appear in column B. Why does my first array formula not expand similar like the second one does?
The INDEX function is one that does not support "iteration" over an array if an array is used as one of its arguments. There is no documentation of this that I know of; it simply is what it is. So the second argument will always default to the first element of the array, which is ROW(A1).
One clumsy workaround to achieve what you require relies on a second adjacent column existing next to the source data* (although it is unimportant what values are actually in that second column):
=ArrayFormula(HLOOKUP(IF(ROW($A$1:$A$4);$A$1);$A$1:$B$4;ROW($A$1:$A$4);0))
or indeed something like:
=ArrayFormula(HLOOKUP(IF({3;2;4;1};$A$1);$A$1:$B$4;{3;2;4;1};0))
edit 2015-06-09
* This is no longer a requirement in the newest version of Sheets; the second argument in the HLOOKUP can just be $A$1:$A$4.
Here is a tip for using vlookup with an array, so that even if the columns are moved later on the formula will still work correctly....
In general, configure the vlookup so that it's reading only 2 columns and returning the second. This can be done by inputting only the 2 columns required, rather than a range and column index.
Example:
Replace the following formula which would fail if columns are moved
=arrayformula( vlookup(C:C, booking!$A:$E ,5 ,false) )
with this formula which will continue to work even if columns are moved
=arrayformula( vlookup(C:C, {booking!$A:$A,booking!$E:$E} ,2 ,false) )
Note, you can also simulate the index function using vlookup.
Example:
Column R:R contains the row index numbers for looking up data in column booking!$A:$A
=arrayformula(vlookup(R:R ,arrayformula({row(booking!$A:$A), booking!$A:$A}),2 , false))
It's a nested array, so it can be helpful to test in stages, eg just the inner part for one example, eg return entry in row 10:
=vlookup(10 ,arrayformula({row(booking!$A:$A), booking!$A:$A}),2 , false)