Index Match with WildCards - Excel [duplicate] - excel

Currently I have a set of cells, and each has, among useless information, a unique identifier. I also have a list of these unique identifiers, as well as what value each identifier corresponds to.
What I would like to do is find which, if any, identifier a cell contains, and then output the corresponding value, below is an example:
http://i.stack.imgur.com/97aKI.png
So where the cell contains "ADC", I would like excel to find where ADC comes up in the reference array, and then return the corresponding value.
If this can be done with a formula or a macro, either would be great. I have tried fiddling with index, match, and search, in various combinations, but nothing seems to be working. I have found creating a massive if statement to be impractical as there are about 70 unique values to search for.
Any suggestions would be welcome!
edit: I was recommended to use vlookup, but I am not looking for an identical match, but instead for a specific value contained within a string. If vlookup does have this functionality then could somebody show me how to put this into practice with my specific example?

One method of a 'reverse-wildcard' lookup can be achieved is with the newer AGGREGATE¹ function. This function can produce cyclic calculation and has an option (e.g. 6) to discard errors. Use this to produce a row number on the match to the cross-reference table with the INDEX function returning the actual value.
      
The formula in B3 is,
=INDEX(F$3:F$5, AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&E$3:E$5&"*", A3, 0)), 1))
Note that ROW(1:3) is the position within F3:F5, not the actual row number on the worksheet. I've also scrambled the Find and Insert values in your original cross-reference table to avoid the perception of an associative lookup match.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Related

excel - Combine VLOOKUP with Datevalue function

Is it possible to use the DATEVALUE function inside a vlookup?
I am trying to lookup a date in a separate sheet but the date is formatted as string so I'd like to use the DATEVALUE function to convert it.
I have played around with putting the datevalue in a few different positions within the vlookup but no luck.
Any help would be greatly appreciated!
Here/screenshot(s) refer -
Of course you can- you just need to know how vlookup works and manipulate accordingly - I provide the solution you have specifically requested, together with 2 other possible ways of looking up without 'parsing to date format' in first instance:
Revision : see here for how to input array formula for different versions of Excel - these are otherwise valid for both 2010/Office 365 compatible version of Excel.
1] Vlookup
=VLOOKUP(G4,IFERROR(DATEVALUE(C4:D6),D4:D6),2,0)
Unlike other lookup functions (e.g. M2-M3, offset etc.) vlookup cannot be used as a reference itself - it requires the entire range to be included and then 'pivots' on the first column. This is why you can lookup datevalue of the single column which contains valid text formatted dates, but once you reference a larger range, datevalue(larger range) will return errors for any value in that range which cannot be converted to a date. Hence the iferror component.
I suspect the fundamental goal is to return the cell corresponding to the datevalue of the text you're looking up - you couldn't be fussed whether it's a vlookup or any other form of lookup. Here are two other methods to achieve this objective:
2] Sum
=SUM(1*(DATEVALUE(C4:C6)=G4)*(D4:D6))
(Uncommon, albeit parsimonious lookup tool)
3] Index
=INDEX(D4:D6,MATCH(G4,DATEVALUE(C4:C6),0))
Closing remarks
Index is typically preferable to vlookup, given the advantage of being able to be used as a reference itself (e.g. you could have offset(index<>) but not offset(vlookup<>)) - this is why index can lookup columns to the left/right of the lookup column (vlookup works to the right only). The only advantage vlookup() has is the approximate search function (final parameter = True to enable). Xlookup() is more versatile; offset() is another 'special / honorary' mention which I have not provided examples for - but also feasible (albeit the latter is has negative stigma associated due to its volatile nature - but that's for another post!)

Excel: Lookup multiple values in one cell and return results in another

I'm trying to find a way to lookup each of several comma separated values in one cell, and return the results as a comma separated list in another cell.
The number of values to lookup is not constant, it may be only one, or several hundred.
Example - Sheet A has the initial values and will hold the returned values. Sheet B is the table with the data to lookup.
EDIT: I've gotten better and learned how to make this a 1-liner. I'll leave my original answer below, but here's my updated one (as this hasn't been accepted or even commented on, yet):
=TEXTJOIN(", ",TRUE,INDEX(SheetB!$A$2:$B$6,MATCH(FILTERXML("<x><y>"&SUBSTITUTE($B2,",","</y><y>")&"</y></x>","//y"),SheetB!$A$2:$A$6,0),2),"")
I think INDEX/MATCH was the key component I hadn't learned yet when I tried answering this before. :)
The FILTERXML/SUBSTITUTE I had learned from another site where it takes in your delimited values and replaces the delimiter and wraps the rest with the needed xml tags for FILTERXML to then return an array of your values.
INDEX/MATCH then does your lookup, first getting the row number via MATCH (note the final value of 0 in MATCH means exact match), then INDEX returns the value of the corresponding matching column (the 2 at the end of INDEX's arguments).
Finally, TEXTJOIN joins the results together with the delimiter of your choice (and the second argument set to TRUE allows it to skip blanks).
As a final note, I think this solution may work without Office 365. FILTERXML appears to have been available as early as Office 2013.
Original, outdated answer follows:
I've been searching for an answer to this myself and was rather dismayed to find your question - exactly the question I have - without an answer.
Almost 4 years late, this answer does require Office 365 Excel, and it's not the most elegant, but here's what I've been able to come up with.
Pick an unused column on your Sheet B (with enough contiguous unused columns to its right to handle spillover of however many values you'll need to be splitting, or use a new sheet dedicated to this) and put this formula into the 2nd row's cell for that column, dragging it down through each cell that has corresponding data back on Sheet A (and assuming your column header "File #s" is column B): =TRANSPOSE(FILTERXML("<x><y>"&SUBSTITUTE(SheetA!$B2,delim,"</y><y>")&"</y></x>","//y"))
Replace delim with your delimiter wrapped in quotes, or a cell reference to a cell that has your delimiter in it. Also, if it's possible to have no value in the corresponding cell in Sheet A, then you'll need to wrap the FILTERXML() function (or the whole thing) with IFERROR().
Then, back on Sheet A in your Results column, use this formula: =TEXTJOIN(delim,TRUE,FILTER(SheetB!$B$2:$B$6,COUNTIF(SheetB!D2#,SheetB!$A$2:$A$6),if_no_match))
Again, replace delim with the delimiter or cell reference with your delimiter of choice. SheetB!$B$2:$B$6 and SheetB!$A$2:$A$6 are your lookup table's columns (and thus extend them to encompass the whole thing). The SheetB!D2# references the column where you put the TRANSPOSE(FILTERXML()) formula. Finally, replace if_no_match with whatever you want to appear if there was no match.
I'd ideally like to find a way that uses a single, self-contained formula, but alas, this is as far as I've managed so far.

excel: Look up value within cell from list of values in other range [duplicate]

Currently I have a set of cells, and each has, among useless information, a unique identifier. I also have a list of these unique identifiers, as well as what value each identifier corresponds to.
What I would like to do is find which, if any, identifier a cell contains, and then output the corresponding value, below is an example:
http://i.stack.imgur.com/97aKI.png
So where the cell contains "ADC", I would like excel to find where ADC comes up in the reference array, and then return the corresponding value.
If this can be done with a formula or a macro, either would be great. I have tried fiddling with index, match, and search, in various combinations, but nothing seems to be working. I have found creating a massive if statement to be impractical as there are about 70 unique values to search for.
Any suggestions would be welcome!
edit: I was recommended to use vlookup, but I am not looking for an identical match, but instead for a specific value contained within a string. If vlookup does have this functionality then could somebody show me how to put this into practice with my specific example?
One method of a 'reverse-wildcard' lookup can be achieved is with the newer AGGREGATE¹ function. This function can produce cyclic calculation and has an option (e.g. 6) to discard errors. Use this to produce a row number on the match to the cross-reference table with the INDEX function returning the actual value.
      
The formula in B3 is,
=INDEX(F$3:F$5, AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&E$3:E$5&"*", A3, 0)), 1))
Note that ROW(1:3) is the position within F3:F5, not the actual row number on the worksheet. I've also scrambled the Find and Insert values in your original cross-reference table to avoid the perception of an associative lookup match.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

If string contains word from list, return value adjacent to list value

Currently I have a set of cells, and each has, among useless information, a unique identifier. I also have a list of these unique identifiers, as well as what value each identifier corresponds to.
What I would like to do is find which, if any, identifier a cell contains, and then output the corresponding value, below is an example:
http://i.stack.imgur.com/97aKI.png
So where the cell contains "ADC", I would like excel to find where ADC comes up in the reference array, and then return the corresponding value.
If this can be done with a formula or a macro, either would be great. I have tried fiddling with index, match, and search, in various combinations, but nothing seems to be working. I have found creating a massive if statement to be impractical as there are about 70 unique values to search for.
Any suggestions would be welcome!
edit: I was recommended to use vlookup, but I am not looking for an identical match, but instead for a specific value contained within a string. If vlookup does have this functionality then could somebody show me how to put this into practice with my specific example?
One method of a 'reverse-wildcard' lookup can be achieved is with the newer AGGREGATE¹ function. This function can produce cyclic calculation and has an option (e.g. 6) to discard errors. Use this to produce a row number on the match to the cross-reference table with the INDEX function returning the actual value.
      
The formula in B3 is,
=INDEX(F$3:F$5, AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&E$3:E$5&"*", A3, 0)), 1))
Note that ROW(1:3) is the position within F3:F5, not the actual row number on the worksheet. I've also scrambled the Find and Insert values in your original cross-reference table to avoid the perception of an associative lookup match.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

simplifying Excel formula currently using INDEX, ROW, SUMPRODUCT and IFERROR

Does anyone have any brilliant ideas to simplify this difficult formula? Don't panic when you see it, I will try to explain.
=IFERROR(INDEX(rangeOfDesiredValues,(1/SUMPRODUCT((rangeOfSerials=$D20)(rangeOfApps=cfgAppID)(rangeOfAccessIDs=cfgAccessID)*ROW(rangeOfDesiredValues))^-1)),"")
Currently I am using SUMPRODUCT to do the equivalent of a VLOOKUP with multiple columns as criteria. Usually that only works with number results, but since I need to find text, I'm using SUMPRODUCT in combination with ROW and INDEX.
Unfortunately when no cell is found, my SUMPRODUCT returns 0. This causes the formula to return the incorrect cell rather than blank. For this reason I am running the result through this calculation:
(1 / result)^-1
This way results of 0 become an error, and other results remain unchanged. I feed this into IFERROR, so that errors become blanks.
Does anyone know how to make this neater? I am not able to create new columns in any of my spreadsheets.
It's always best to avoid using multi-condition summing functions like SUMPRODUCT when you want to find a single value (it would obviously give you an incorrect result or error if there's more than one row which matches all three conditions, I assume you expect one match at most here?). ROW function can also be problematic if you insert any rows in the worksheet.....
There are several approaches that can work. For a single formula, using MATCH is the most common - MATCH will only give the correct position or an error so no problems with zero values. That would look like this:
=IFERROR(INDEX(rangeOfDesiredValues,MATCH(1,(rangeOfSerials=$D20)*(rangeOfApps=cfgAppID)*(rangeOfAccessIDs=cfgAccessID),0)),"")
That's an "array formula" that needs to be entered with CTRL+SHIFT+ENTER......or you can make it into a regular formula with an extra INDEX function like this
=IFERROR(INDEX(rangeOfDesiredValues,MATCH(1,INDEX((rangeOfSerials=$D20)*(rangeOfApps=cfgAppID)*(rangeOfAccessIDs=cfgAccessID),0),0)),"")
A third alternative is to use LOOKUP which doesn't need "array entry"
=IFERROR(LOOKUP(2,1/(rangeOfSerials=$D20)/(rangeOfApps=cfgAppID)/(rangeOfAccessIDs=cfgAccessID),rangeOfDesiredValues),"")
That differs slightly from the previous versions in the case of multiple matches - it will give you the last match rather than the first in that scenario (but I assume you have only one match at most, as stated above).
Finally, if you don't mind using helper columns you could simplify the formulas considerably. Just use a "helper" column to concatenate the three criteria columns separated by dashes and then you can use a simple VLOOKUP or INDEX/MATCH, e.g.
=IFERROR(INDEX(rangeOfDesiredValues,MATCH($D20&"-"&cfgAppID&"-"&cfgAccessID,Helper_Column,0)),"")

Resources