Advanced match with more than one critera - excel-formula

I would like to autofill a table from a source table. The solution needs to take into consideration two criterias. The first is a match on Column 1, top node ("One", "Two", etc) and the second is that it needs to match the sub-node in Column 1 ("AA", "BB" etc). Given a match, the corresponding value in Column 2 should be fetched. This value should be populated in an identical table in the destination. Hence the destination table is where we match the nodes to, and the result go into the yellow cells.
How do I do this double criteria solution?
Thank you

Related

Excel - Find matching values and copy different cell

I have 2 Excel spreadsheets and both sheets have a "Code" field and value that may or may not exist in both. In sheet1 and sheet2 there is also an "ID", i'm hoping that if the "ID" is populated in sheet1 and if the matching code exists in sheet2, a query can transfer the "ID" to sheet 2
SHEET1
|
SHEET2
I can find the matching values using vlookup but my issue is getting the ID field to populate
=VLOOKUP(A1,Sheet1!A:A,1,FALSE)
Instead: =VLOOKUP(A1,Sheet1!A:B,2,FALSE).
From Microsoft's help on Vlookup:
How to get started
There are four pieces of information that you will need in order to build the VLOOKUP syntax:
The value you want to look up, also called the lookup value.
The range where the lookup value is located. Remember that the
lookup value should always be in the first column in the range for
VLOOKUP to work correctly. For example, if your lookup value is in
cell C2 then your range should start with C.
The column number in the range that contains the return value. For
example, if you specify B2:D11 as the range, you should count B as
the first column, C as the second, and so on.
Optionally, you can specify TRUE if you want an approximate match or
FALSE if you want an exact match of the return value. If you don't
specify anything, the default value will always be TRUE or
approximate match.
Pay special attention to parameters 2 and 3.
Note that number 2 "The range where the lookup value is located" should be the full range where the first column of the range has the values to lookup and the last column of the range should contain the values you want to return. So your A:A only having one column, will only lookup and return values in column A. You want values returned from column B so it must be included as well, to become A:B.
Since column B is the second column in the lookup range of A:B then your third parameter will be 2 which leads to the vlookup at the top of this answer.
This is what you are doing:
VLOOKUP(A1,Sheet1!A:A,1,FALSE)
(I will only talk about Sheet1!A:A and 1)
You are looking into column A and from there you are taking column number 1 (which is column A).
What you should be doing, this this:
VLOOKUP(A1,Sheet1!A:B,2,FALSE)
Look into table, made up of columns A and (up to) B, you will automatically look into the first column, and you return the value you find in column number 2 (which is column B).

Pull cell data while other cells within row match a string

I'm using google sheets for a work project, and I'm trying to pull data from a cell that is in a row with 2 cells that match what I'm looking for.
For example: I have 8 columns and 5600 rows in sheet 2. I want to pull the data from column "D" but only if the data in columns "A" & "C" match what I'm looking for. Say column "A" is filled with days of the week, and column "C" is filled with first names, and column "D" is filled with an ID number. I want the ID number from column "D", but only from the rows in which column "A" = "Thursday" & column "C" = "Jeff". There will also be some rows that share columns "A" & "C", but have a different number in column "D", and I would like to pull those as well.
Here is my attempt where I was able to grab the day of the week:
=INDEX('sheet2'!A:A,MATCH((INDIRECT("RC[-5]",0)),'sheet2'!C:C,0),)
(the indirect function is there because the first name I want to match for is always going to be 5 cells to the left of where this function is)
And here is my attempt where I was able to grab the ID number:
=INDEX('sheet2'!D:D,MATCH((INDIRECT("RC[-5]",0)),'sheet2'!C:C,0),)
So, I want to be able to call the second function above, but only if the first function evaluates to "Thursday", for example.
To me this boils down to two different problems
Q1) A multiple criteria lookup (INDEX+MATCH)
Q2) Returning several values when multiple rows match your criteria
Assume that the weekday is 6 cells to the left of your function and the first name 5 cells to the left. I have also restricted the range from searching the whole column. Adjust as needed, but the complete column is a bit too much for Excel to handle.
A1) This simple lookup will deal with the multiple critera issue, but doesn't fetch duplicates of the name and weekday combination.
=INDEX(sheet2!D2:D12,MATCH((INDIRECT("RC[-6]",0)&INDIRECT("RC[-5]",0)),sheet2!A2:A12&sheet2!C2:C12,0))
A2) This formula would list all the results in the same cells delimited by a comma, looking like this "121208,445555,445553", not on separate rows.
=TEXTJOIN(",",TRUE,(IF((INDIRECT("RC[-6]",0)=sheet2!$A$2:$A$12)*(INDIRECT("RC[-5]",0)=sheet2!$C$2:$C$12)*(1-ISBLANK(sheet2!$D$2:$D$12)),sheet2!$D$2:$D$12,"")))
Edit after comment feedback: Some versions of excel requires you to apply this formula with Ctrl+Shift+Enter instead of just Enter for it to work properly.
If you need to have all the matches for a pair of criterias stacked on separate rows I would recommmend that you check out the Power Query tool (native in the latest versions of Excel). This would be a relatively easy task for PQ to handle by merging tables with join kind "Left Outer".

VLOOKUP value not available to formula or function but it should be

I am using the following formula:
=VLOOKUP(E9, 'Raw data'!$A$1:$I$45857, 9, FALSE)
I have two tabs and I want one column in my first sheet to lookup the # value found in 'raw data' associated with the ID number found in column E (data begins on cell E9). my second tab, 'raw data', includes that same field as found starting on E9 in sheet 1 within the data range A1:I45857. The column I want returned from 'raw data' is the 9th column. I want to be exact matches only.
What I think excel is thinking - look for e9 in the array 'raw data' and when I see it, return the value that I find in the 9th column of that row within array 'raw data'.
What excel is saying - A value is not available to the formula or function
I am confused because the value is in fact available within that array. when I filter and search for just one of the IDs, I find it in both sheets. The data type is number for both columns and there are no rogue spaces or anything...
My goal is ultimately to take a subset of ids and look at the difference between the # found on sheet1 and the number found on 'raw data'. I am Vlookup-ing so that i can grab the # value on 'raw data, set it right next to the # i am comparing it to on sheet1 and then I can pivot the data to aggregate both of those numbers based on ID and create a calculated field showing the % difference between the two.
Any input on how to fix my vlookup or a workaround to join my # from 'raw data' to sheet1 based on a common ID is MUCH appreciated.
I recommend that you look into the combination of INDEX & MATCH, rather than VLOOKUP, for situations like this. VLOOKUP has 2 main flaws: (1) you have to order your data so that your search term is the left-most column of a continuous data block [as you have just seen]; and (2) it is volatile, meaning that when a column is inserted within your data block, it will no longer properly 'count' the number of columns to move to retrieve your data.
MATCH is like half of VLOOKUP. You give MATCH a specific column or row, and a value to search for, and it will simply return the number of cells in it had to move to find that value.
=MATCH(A1,B:B,0)
This says 'look at B:B, and tell me what row the value of A1 appears on'.
INDEX is like the other half of VLOOKUP. You give INDEX a group of cells (either a row, column, or a 2D range), and a specific row number (plus potentially a column number), and it will return the value for that cell.
=INDEX(C:C,5)
This gives you the value of cell C5, which is the 5th row found in the column given to INDEX. Combine these two formulas and it will return the value of column C, where column B matches A1:
=INDEX(C:C,MATCH(A1,B:B,0))
This formula gives an identical result to
=VLOOKUP(A1,B:C,0)
VLOOKUP looks simpler here, but INDEX & MATCH is much more versatile - in your case, you wouldn't have needed to reorder your data to get it to work, you could have used the formula:
=INDEX('Raw Data'!I:I,MATCH(E9,'Raw Data'!E:E,0))
Once you get into the habit of using INDEX / MATCH over vlookup, you will find that your data is a lot more flexible to manage.
Got it to work by making my ID field in 'raw data' the leftmost column.
You don't need to start the Vlookup in column A. If the ID column is not in column A, Vlookup can still work, as long as the ID column is to the left of the column you want to return. So, if you want to return the value from column I, and the ID column is in column F, you can leave the table as it is and change the Vlookup to
=VLOOKUP(E9, 'Raw data'!$F$1:$I$45857, 4, FALSE)
This will look for the match in column F and returns the value from the fourth column, which is column I.

Excel: How to find the first row's value of a column depending on where to find a given number in another row of the same column

Imagine a 100x100 table. I have to find a given value in the first column. Then I have to check the row contains that given value, and I have to find the column where the value is 1 (every row has only one cell with value 1), and I need the first row's value of that column. I've tried several lookup functions (vlookup, hlookup, index match match, etc). No results. Is it possible using only functions and no VBA at all?
I'd prefer to use INDEX rather than INDIRECT, it's not volatile and it's more robust in dealing with added rows or columns than "hardcoded" values like "B" and "D", so assuming data in A1:Z100 you can use this formula for the match, assuming a search value of "x"
=MATCH(1,INDEX(B2:Z100,MATCH("x",A2:A100,0),0),0)
...and you can add an extra INDEX function to retrieve the first row value for that column
=INDEX(B1:Z1,MATCH(1,INDEX(B2:Z100,MATCH("x",A2:A100,0),0),0))

How to create result table with vlookup from merged cells

I have this data table and i want another result table. when I write name of state ,result table can show all of company with data1,data2 and data3.I trying use vlookup but because there are merged cells the formula just show first row.
how can I fix problem?
If I'm understanding correctly, you want to set up a lookup range so that when you enter a particular state, you can see the data for all the companies that have data in that state. Here is one way to do that.
The first thing you would need to do is set up three columns to the left of the original table:
The first column holds the name of the state associated with each row of data
The second is an index that counts off the number of data rows in each state
The third combines the first two columns to produce a unique key value for each row in the table.
All the values in these three columns can be assigned by formula. The picture below shows the formulas for the first row of cells A9:C9, which are then copied down through row 27.
The next step is to lay out the new table, which is in cells Q8:U27 in my example.
There are several thing to note about the setup. First, the state that will be displayed is entered in cell Q9, which I've highlighted in yellow. To the left of the table, in column P, I've entered item numbers from 1 to 19, which will be needed to construct the key values for the lookups. The lookup formulas themselves are in cells R9:U27; in the picture, the formulas for the first row (R9:U9) are shown (they are then copied down through row 27).
It's worth taking a moment to look more closely at one of the lookups. Here is the formula for the first company name in cell `R9'.
=IFERROR(VLOOKUP($Q$9&$P9,$C$9:$N$27,4,0),"")
Looking at each of the arguments of the VLOOKUP in turn, $Q$9&$P9 concatenates the state name in cell Q9 with the item number (1 in this case), yielding the lookup value 'California1'. The lookup table is defined as the range $C$9:$N$27 - column C of that range is what the lookup value is matched against. The third argument is the column from which to return a value if the lookup is a match. The number 4 here corresponds with the company name column of the original table. Finally, the last argument is 0 (or equivalently, FALSE) indicating an exact match is required.
Finally, the VLOOKUP function is wrapped inside IFERROR. This catches the #N/A that would otherwise be returned when no match is found, replacing it with an empty string ("").

Resources