adding wildcard to look up formula? - excel

I am using the following formula as part of a multi result look up function. I have several of these formulas posted into one row each beneath the other, so if I type catering into cell K22 on sheet 1 my formula then looks up that matching word from column b on sheet 2 and produces the name in column a. The formula also includes duplicating this lookup a few times to fetch other values from other columns with the same matching result.
so for instance my columns on sheet 2 look like:
Name Description Location Number
Amy hotel london 1
Dave hotels manchester 2
Mike catering Birmingham 3
What I want to do is to use wild cards around my cell K22 in this formula to show if the descripion word I type in is like hotel; i.e. hotels, hote ... etc then find the result?
...
I know this can be done using index match but can I use them with the following code I have? at the moment this is an array formula but I get no result when I try to do it like this. can someone show me where I am going wrong, tanks
=IF(ISERROR(INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),1)),"",INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),1)) & " - " &IF(ISERROR(INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),3)),"",INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),3)) & " - " &IF(ISERROR(INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),4)),"",INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),4

Although you can use wildcards in the lookup value within a MATCH function (and in other contexts), you can't use them here. When using wildcards with a direct comparison with = like you have, i.e.
Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*"
the * is interpreted as a literal asterisk not a wildcard
Replace all instance of the above with this
ISNUMBER(SEARCH(Sheet1!$K$22,Sheet2!$B$1:$B$7))

Related

Excel Countifs - Search Text in String

I have a column (let's say B1) in an Excel form that shows some products like this:
Sand Systems
Gas Systems
Blenders
Other
Other 2
Other 3
Other 4
I need to count the rows that doesn't contain the text "Other #" (# being a number), in other words, "Sand Systems", "Gas Systems", "Blenders" and "Other" = 4.
The solution so far was using an auxiliary column with the formula =SEARCH , but how to make it ignore the "Other" cell and accept "Other #"? Additionally, I wouldn't like to use an auxiliary column, but a cell with the =COUNTIF formula. Any advice?
One approach is something like:
=COUNTIF(A1:A7,"<>" & "Other *")
This returns 4, which is the expected result?
Using the whole column reference will return the incorrect result, just FYI. If you're dead set on using whole column references use Ron Rosenfeld's formula:
=COUNTA(A:A)-COUNTIF(A:A,"Other *")
=COUNTA(A:A)-COUNTIF(A:A,"Other *")
Count them all, then subtract the one's that contain Other followed by space and anything else.

excel: if cell contains multiple criteria then return multiple criteria, nestled?

I have 4 criteria lists that look like this:
A B
Name Category
Name Category
Name Category
And a MasterList like this:
A B
stuffNAME Category
NAMEstuff Category
NAME Category
I would like to know if there is a formula that can search through each criteria list based on the MasterlistA column for "NAME" and return the appropriate "Category" in MasterlistB.
As an example:
I'm looking to return MasterlistB based on MasterlistA
Criteria List:
A B
NBC NBCU
Disney ABC
Masterlist:
A B
NYC NBC 20998 NBCU
NJ2987 NBC NBCU
Disney Florida99 ABC
I'm simplifying, but in reality the criteria lists all refer to different masterlist columns as well. Trying to get the matching/searching part down first.
Given a setup as shown in #ScottCraner 's answer:
In cell E1 and copied down:
=IFERROR(LOOKUP(1,1/COUNTIF(D1,"*"&$A$1:$A$2&"*"),$B$1:$B$2),"No Match")
This is a regular formula and does not require array entry.
You can do this using VLOOKUP, nested with the IFERROR statement.
I am assuming each table is starting on A1, in sheets called Sheet1, Sheet2, Sheet3, and Sheet4. You may need to adjust references to point to appropriate tables.
The basic formula to find the category which matches your name, is simply [assuming your search term is on a new sheet on A1, let's say Sheet5, with the rest of your final data table]:
=VLOOKUP(A1,'Sheet1'!A:B,2,0)
This simply takes the value in A1 [the search term], tries to find it in column A of sheet 1, and if it does find it, takes the first matching row, and returns the value on the 2nd column in [column B, with the category].
If that fails, you simply put that inside of IFERROR, which attempts to calculate something, and if it creates an error, returns something else, like so:
=IFERROR(VLOOKUP(A1,'Sheet1'!A:B,2,0),"NO MATCH FOUND")
Now to use the IFERRORS to first attempt to find a match on Sheet1, then Sheet2, etc., put the following:
=IFERROR(VLOOKUP(A1,'Sheet1'!A:B,2,0),IFERROR(VLOOKUP(A1,'Sheet2'!A:B,2,0),IFERROR(VLOOKUP(A1,'Sheet3'!A:B,2,0),VLOOKUP(A1,'Sheet4'!A:B,2,0))))
To search for only a partial match, you can use the following:
=VLOOKUP("*"&A1&"*",'Sheet1'!A:B,2,0)
The "*" act like wildcards, and if they are included in front of and behind your search term [in this case, A1], then anything that contains your search term, regardless of its position in a cell, will be considered a match. You can replace A1 in all of my above formulas with this revised wildcard match to check for partial matches in any of your sheets.
To search a list of items, which exactly match a part of your search term
You could probably do this with an array formula, but because you have multiple data tables, I think the easiest solution is to use a helper column next to each of those tables, to create a unique ID which actually matches to your Master List. ie:
On Sheet1 [and all other category sheets], insert a new column in between A & B; this column will trace back from column A, to match a Name from your Master List on Sheet5, like so [starting in B1 & copied down]:
=VLOOKUP("*"&A1&"*", 'Sheet5'!A:A, 1, 0)
Your revised formula in your master sheet would now look like this:
=IFERROR(VLOOKUP(A1,'Sheet1'!B:C,2,0),IFERROR(VLOOKUP(A1,'Sheet2'!B:C,2,0),IFERROR(VLOOKUP(A1,'Sheet3'!B:C,2,0),VLOOKUP(A1,'Sheet4'!B:C,2,0))))
Rather than placing the four lists side-by-side like:
Stack them on top of each other like:
The its as simple as:
=VLOOKUP("David",A1:B12,2)
So here is the basic formula to get what you want:
=INDEX($B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & $A$1:$A$2 & "*",D1))),1))
if you have 2010 or later. If you have 2007 and earlier than you will need to use the following array formula:
=INDEX($B$1:$B$2,SMALL(IF(ISNUMBER(SEARCH("*" & $A$1:$A$2 & "*",D1)),ROW($1:$2)),1))
It being an array formula it must be confirmed with Ctrl-Shift-Enter.
In the picture, the first formula is Column F, the second in Column E
You will need to add nested IFERROR() Functions for the various sheets.
=IFERROR(INDEX(Sheet1!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet1!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet2!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet2!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet3!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet3!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet4!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet4!$A$1:$A$2 & "*",A1))),1)),"NOT HERE"))))

Index/Match with multiple possible answers?

There's a question about how to return some info in Excel, COUNTIFS for VLOOKUP. from #THATNewbie.
Here's a quick summary:
They have this table:
Report Name User Name Report Category
Report 1 John Smith Sales
Report 1 Jack Black Sales
Report 1 Connie Rae Sales
Report 1 Brain Bonds Sales
Report 2 John Smith Sales
Report 2 Connie Rae Sales
Report 3 Jack Black Inventory
And they would like to return the "Report Name" based on User Name and Report Category.
My first thought was just to use Index/Match (as an Array)...however, I realize that if I use "John Smith" and "Sales" to look up the Report Name, there's two possible outcomes: Report 1 and Report 2. Index/Match will always return Report1 (or whatever comes first, going down that column).
My question is: Is there a way to write the Index/Match formula to check if it's already found Report1 and therefore to go to the next match (Report2)?
Here's a screenshot to help visualize. As you can see, the Index/Match correctly finds Report1 in C12, but also in C13. Can you have the formula "look above" and if it's the answer that it WOULD return, to skip that and look for the next? Does that make sense?
You can try something like this:
=INDEX(Report_Name,MATCH(The_User&":"&The_Category,User_Name&":"&Report_Category,0))
The idea is to concatenate user name and report category into a single search item. (I added a colon char as a delimiter; this was optional and could possibly be omitted.) Then use MATCH to get the index of the matching item, and INDEX to convert the index to a specific report.
Hope that helps.
Unfortunately there is no way (to my knowledge) to do this. You will have to add some sort of unique identifier to each row, or a value that helps define it uniquely. For example, you could add a new column with this function
=COUNTIFS($B$2:$B2, "=" & $B2, $C$2:$C2, "=" & $C2)
What this will do is count the total number times that that specific grouping has shown up, and effectively act as a pseudo ID for it. Then you can add that item to your Index/Match
Then in the second table you showed in the image, you just repeat the count function in the match, so you will have
=INDEX($A$2:$A$8, MATCH(1, (A12 = $B$2:$B$8) * (B12 = $C$2:$C$8) * (COUNTIFS($A$12:$A12, "=" & $A2, $B$2:$B2, "=" & $B2) = $D$2:$D8), 0))
This is an array entered forumla
My question is: Is there a way to write the Index/Match formula to
check if it's already found Report1 and therefore to go to the next
match (Report2)?
Yes, but a simpler way it can be done is using index & small.
Index & small
Need to CTRL+SHIFT+ENTER. Copy down for remaining rows.
{=INDEX($A$2:$A$16,SMALL(IF(A19=$B$2:$B$16,IF(B19=$C$2:$C$16,ROW($B$2:$B$16)-ROW($B$2)+1),""),ROW(B2)-1))}
Where A19 & B19 contain cells for search criteria.
Using Index & Match;
This could possibly be simplified but shows the steps.
Add another column alongside the search criteria area & change the formulas as below.
Need to CTRL+SHIFT+ENTER.
Column C (Report Name);
Following for the first row or search criteria item only
{=INDEX($A$1:$A$16,MATCH(A21&B21,$B$2:$B$16&$C$2:$C$16,0)+ROW(A2)-1)}
Copy following down for the remaining rows items.
{=INDEX($A$1:$A$16,MATCH(A22&B22,INDIRECT(CONCATENATE("B",E22,":","B16"))&INDIRECT(CONCATENATE("C",E22,":","C16")),0)+ROW(INDIRECT(CONCATENATE("B",E22)))-1,1)}
Column E - helper column. Helper column returns the start of the next row.
First row item is N/A.
Following for 2nd or search criteria item only.
{=MATCH(A22&B22,$B$2:$B$16&$C$2:$C$16,0)+ROW(A2)}
Following copy down for remaining rows.
{=MATCH(A23&B23,INDIRECT(CONCATENATE("B",E22,":","B16"))&INDIRECT(CONCATENATE("C",E22,":","C16")),0)+ROW(INDIRECT(CONCATENATE("F",E22)))}
This however does assume the search criteria is the same, unlike the other question referred to. If search criteria is different or more complex refer to
COUNTIFS for VLOOKUP

Find partial match between two columns and return a third column

I'd like to create a formula that looks for a partial match in two columns in two different Worksheets, and if there is a partial match between the two columns, it returns the value of a different column in Worksheet 2.
Example:
Sheet 1 Column A:
Dev
Tim
Jon
Sheet 2 Column A:
Development
Timothy
Jonathan
If there is a partial match as there is in these fields, I want it to return the value from Sheet 2 Column B.
Currently I have the following formula:
=INDEX(ValueIWant,MATCH(A1,ColumntoPartialMatchAgainst,0))
However, this returns the "ValueIWant" field only when there is an exact match.
How can I modify this formula to work with even a partial match?
Please try:
=VLOOKUP(A1&"*",`Sheet 2`!A:B,2,0)
Note this deliberately only adds a wildcard (*) to the end of the Sheet 1 values to reduce the risk of a match with something like estimate.
To achieve the desired result you should concatenate wildcard(s) to the value to search. In your formula, instead of A1, please try:
A1 & "*" - if you want to match only the beginning of array values (like in your sample data)
"*" & A1 & "* - to match any part of array values

Select all cells in column B where Column A in that row contains a specific text

Basically I have a price list where I want to average the price of all the items on the list that contain my keyword.
The keyword is keyword, price column is B and item description in which to look for keyword is in column A.
I'd like to have a formula like
=Average(data_table,all cell B from row i (i,B) where (i,A) contains keyword)
To Simplify, I added a picture. I tried the suggested solutions below but none worked. I should get 15.33 (Assuming the indices go from 1 to 5 and not from 2 to 5 as in the picture)
Use AVERAGEIF, which I believe became available in Excel 2007. This will handle "keyword" by itself, or as part of a longer string like "my keyword".
=AVERAGEIF(A2:A5,"*keyword*",B2:B5)
To refer to a cell containing a keyword, D1 in this example, use:
=AVERAGEIF(A2:A5,"*" & D1 & "*",B2:B5)
I would suggest the following:
=AVERAGEIFS(B:B,A:A,"*"&"keyword"&"*")
Cheers!
::Edit for Updated Question::
With your new layout, use the following:
=AVERAGEIFS(B1:B5,"*"&D1&"*",A1:A5)

Resources