Combining a text search and a lookup table - excel-formula

I have a column of strings (descriptions of errors manually entered by personnel) (A2:A1000) that I'd like to search for specific words (to create categories based on the description), and based on the words found, input a specific case value (a category label) into a second column (B2:B1000). Currently this is being handled by nested if statements of the form
B2=if(isnumber(search("Flag Word 1",A2)),"Case Word 1", if(isnumber(search("Flag Word 2",A2)),"Case Word 2", ...))
Obviously for a large number of flag/case words, this gets messy pretty quickly. I'd like to be able to create a lookup table, have excel search column A for words in the lookup table, and return the corresponding value, but I'm not sure if this is possible - it doesn't seem that way without resorting to VBA. Are there any alternative methods to achieving the same result?
Thanks,
~P

You could try an array formula like this one (has to be entered with Ctrl-Shift-Enter):-
=INDEX($D$2:$D$4,MIN(IF(ISNUMBER(SEARCH($D$2:$D$4,A2)),(ROW($D$2:$D$4)-ROW($D$1)))))
It assumes that there is a list of keywords in D2:D4, and will give you the first one in the list which is contained in the string in A2. You could change MIN to MAX to get the last match.

Related

Return array based on titles

I'm, looking for a way to return an array of text based off of titles or headers if you will. My brain isn't working today and I keep struggling to find the best method. I originally was going to have a bunch of IF statements and ran into problems, and I can't seem to figure out if Aggregate is a viable method.
Essentially if "Title 1" is selected from a drop down I would like to return the names within Title 1, and so on. If "All" is selected I would like all to populate from each title. The speed bumps I have is that some names repeat and I only want to show each name once always in alphabetical order. Can someone please get me started on how to tackle this?
In Excel O365 with the FILTER function, you can do this with a helper column (which you can hide, or position elsewhere).
I created a Table and am using structured references, but you can change to ordinary addressing if you prefer.
TitleList is a named range that includes all or your titles (presumeably you will use this for your dropdown).
For the Helper Column, I have it adjacent to your Names column with the formula:
=IF(OR(A2=TitleList),ROW(),B1)
This creates a unique number for each title.
Then, for your formula, under the dropdown, you can use:
=FILTER(Table3[Names],(Table3[Names]<>G1)* (Table3[Index]=XLOOKUP(G1,Table3[Names],Table3[Index])))
where G1 contains the dropdown
With Column B visible:
Some with O365 do not have the FILTER function. If you do not have the FILTER function, you can use:
=INDEX(Table3[Names],AGGREGATE(15,6,1/(INDEX(Table3[Index],MATCH(G1,Table3[Names],0))=Table3[Index])*ROW(Table3)-ROW(Table3[#Headers]),ROW(INDEX($A:$A,2):INDEX($A:$A,COUNTIF(Table3[Index],INDEX(Table3[Index],MATCH(G1,Table3[Names],0)))))))
EDIT
To return a non-duplicate list of ALL of the names, add ALL to TitleList and use this formula instead.
This formula makes a special case for ALL and filters out the rows that contain a Title
=IF(G1="ALL",UNIQUE(FILTER(Table3[Names],COUNTIF(TitleList,Table3[Names])=0)),FILTER(Table3[Names],(Table3[Names]<>G1)*(Table3[Index]=XLOOKUP(G1,Table3[Names],Table3[Index]))))
.imgur.com/apkHh.png

Index Match Partial Criteria

I'm trying to Index/Match a column with shortened criteria. The idea is to Pull the Line of Business from the column without producing dozens of "duplicate" Unique Lines of Business.
Currently, I get a list like:
Whereas I just want:
I don't want to use a fixed list lookup, as the data is varied enough to not be practical using a fixed list
The ARRAY formula so far: {=IFERROR(INDEX($C$1:$C$155,MATCH(0,COUNTIF($Q$156:Q156,$C$1:$C$155)+COUNTIF($C$1:$C$155,$C$1:$C$155<>1),0)),"")}
Is there a way to search in the text for the company name without creating a new column?
You would need to use some sort of formula like this to filter your countif query =IF(ISNUMBER(SEARCH("company",A1)),"Company "&MID(A1,FIND("company",A1)+8,1),"").
This code searches your list for the word company and then outputs the word "Company" then searches 8 positions to the right from the start of the word and returns the number.

Can I INDEX,Match,Search one cell for two separate lists and return the result that has both?

Backstory
I have been tasked with creating a system that fills in excel files for the user based on them entering minimal information. This includes categories, of which we have too many. I have a function that searches a cell for one list of criteria and returns the adjacent cells result. But with so many criteria there are often times where a wrong result is returned.
What I want to do is use a second criteria to make the search more specific.
My current setup
The formula that I can currently using is:
=INDEX(Categories!D$3:D$53,MATCH(TRUE,ISNUMBER(SEARCH(Categories!C$3:C$53,I2)),0))
So whatever the user enters into I2 is cross-referenced with Categories!C$3:C$53 and if there is a match then Categories!D$3:D$53 is returned.
Image
So you can see how its set up in the picture, purple is the second search criteria I'd like to add.
I did try to add a match function at the beginning so IF another cell = Cordless Power Tools then I could narrow down the search. But that would mean a separate formula for every category and sub-category of which there are hundreds.
Thank you for any help that you can be.
Edit - I have realised that what I want is actually much more complicated than I had originally thought.
What I want is to be able to search a cell for a match in column B and then if there is a match then only search that section in C to return adjacent value in D.
For example. I have a tool - an 18v 115mm Angle Grinder. So my search string is "18v 115mm Angle Grinder", The formula would then search this string for a match in column B which it does (B61) so then the formula would search for a match in "18v 115mm Angle Grinder" in only column C61 and C62, finding a match and returning "Grinders" from D61.
I realise this looks pointlessly complicated but there are hundreds of categories I'm trying to implement this in and there are simpler titles in all of them so I'm trying to narrow the search down so I don't have to use multiple formulas.
Thank again for any help anyone can be.
If you want to add another condition in the search, say, that column A matches what's entered by the user in J2, add the condition to your search using the * operator that applies a logical And on different conditions. But the only thing is that its result is a number 1/0 instead of True/False.
=INDEX(Categories!D$3:D$53,MATCH(1,
ISNUMBER(SEARCH(Categories!C$3:C$53,I2))
* (Categories!A$3:A$53 = J2)
,0))
p.s. dont forget to parenthesize the factors when using * as logical operator.

Display value if text strings from two ranges match

I have two worksheets in Excel. One contains the rankings:
:
The other one the matchups (daily updated automatically)
The purpose is to display the rank of each respective team in two columns next to the matchups. One of the problems is that the text strings are not exact matches (limitation of the webquery).
So I need to find a formula for when there is a string of the table in Rankings that approximately matches the specified cell for the team in matchups and then display Rank (column 1 on Rankings) next to it.
So far I've got this in the cell where the ranking is supposed to go.
=VLOOKUP("*"&qry!B5&"*";Sheet1!A3:C369;1;0)
But it just results in the string "rank" from the table header in Rankings.
Any ideas?
Several things:
Vlookup will try to find a match in the first column of the lookup table and can return a value from a column to the right. Your lookup table has the desired return value in the first column and the lookup values in the second column. Therefore, Vlookup will not work in this scenario. You can use a combination of Index and Match, though.
the * wildcard before and after the lookup value mean that the value in the lookup table can have any text before and after the text already in your lookup value. In your case, the lookup value has more text than the text in the lookup table. So the wildcard is not helping. Example: you have "353 Virginia" and you want to find this in a column that has only "Virginia". Wrapping "353 Virginia" in wildcards will add no value, because the text that you want to match is actually shorter than the text you are starting out with. You need to remove stuff from the lookup value instead of adding wild cards.
If the data for the rankings comes from a web query, you need to do some work to clean up that data, so it is fit for the lookup into your other table.
In addition to the number at the beginning, there are also two characters at the end of some cells that I cannot identify. These need to be stripped out, too, before you can do the lookup.
Assuming that all cells contain three digits and a space at the beginning you can use a formula approach
=TRIM(MID(SUBSTITUTE(B5;" ##";"");5;99))
Substitute will remove the trailing characters. I don't know what they are exactly, some web related special characters, so for the exercise here I have used ## instead of the A thing and the chevron. Copy and paste the web characters from one of your cells to the formula. With data coming from the web you may also want to check for leading and trailing white space, non-breaking space characters and other invisible characters.
You can use the "cleansing" formula as the basis of a lookup or, if the formula above sufficiently cleans the data, then you can use it in an index/match combo like this:
=index(Sheet1!$A$3:$A$369,match(TRIM(MID(SUBSTITUTE(B5;" ##";"");5;99));Sheet1!$B$3:$B$369;0))
Without seeing the actual data in a spreadsheet it is hard to tell if the formula cleanup is sufficient. You may need to do more work until a lookup returns the desired value.
If the data is coming from the web, I strongly suggest that you look into Power Query as a tool to get the data from the web into your spreadsheet. Power Query is a free add-in for Excel 2010 and 2013 and is built into Excl 2016 as "Get & Transform". It can connect to many data sources, including tables on a web page, and it has very powerful mechanisms to clean data for further processing. Once a Power Query is set up and working, all you need to do is refresh the query to load new data from the web site.

Excel function to match a substring from text with a list

I'm trying to extract the substring from an entire string and rename it using v-lookup. I don't want to use the text to column function.
The textstring in column A:
Adf_ROCLeader_BAN_728x90_CPM_STD _BRD _NRT_DCK
MMC_ContextualLarRec_BAN_336x280_CPM_STD _LDS _RTG_DCK
Adf_ROC_DLBD_728x90_CPM_STD_DRS_NRT_NOR_DCK
Vlookup list
BRD - Branding
DRS - Direct Response
LDS - Leads
So basically, the function would need to see if the cells in column A contain BRD, DRS, or LDS (list) and than rename it to the names corresponding with the list.
I tried using 3 formula's nested in one: Search, Mid, and Vlookup, but the Search function doesn't seem to work on a list.
Thank you in advance.
With your lookup values (i.e. BRD, DRS, LDS) and corresponding replacements (i.e. Branding, Direct Response, Leads) in D1:D3 and E1:E3 respectively, and the first string on which you wish to perform the replacement in A1, enter this formula in B1:
=IFERROR(SUBSTITUTE(A1,LOOKUP(2^15,SEARCH($D$1:$D$3,A1),$D$1:$D$3),LOOKUP(2^15,SEARCH($D$1:$D$3,A1),$E$1:$E$3)),A1)
Note that, if none of the search strings is found, the cell entry is returned unchanged. Also note that, since you gave no cases in which more than one of the search strings is present in a given entry, this is assumed to not be possible, and no accounting has been made for it in the above solution.
Regards

Resources