Using VLOOKUP and not only match on first value - excel

I'm trying to use VLOOKUP to match activities with product codes, but run into an issue since VLOOKUP always returns the first match. I did a mockup below to describe my issue. To the left, I have a table with activity names and product codes.
To the right, in column G, I want to, based on matching activity names in column F with activity names in column A, assign the activities product codes from column B.
When I use VLOOKUP, it only matches with the first activity name and give all the activities with the same name the same product codes. I need them to get different product codes even if they have the same name. I want my function to "take the next one" on the list, when the first one is taken.
Should I try to use another function to solve this? Is it impossible with VLOOKUP? My 'real' document has like 2000 rows, and the solutions I found on Youtube was not good to scale.
Thanks in advance. I'm new to here so if I should clarify my question in any way, feel free to tell me.

If the raw is around 2,000 rows, you can use a nested index match with helper columns.
Add a rank in column C with the formula =COUNTIF(A2:$A$2,A2)
Then apply the same ranking in your output part as well (Ensure Activity Name is sorted so that the formula works), Output rank formula =IF(J2=J1,I1+1,1)
Formula that lists out the Product Code {=INDEX($B$2:$B$3190,MATCH(I2,IF($A$2:$A$3190=J2,$C$2:$C$3190),0))}
This is an array formula, you get the curly brackets by hitting control+shift+Enter instead of just Enter upon keying in the formula

If you are using excel 365, you can use UNIQUE formula.
=UNIQUE(A2:B18)

Related

Excel: Categorizing cells based on a partial match

UPDATE: found an answer to my problem through this website: https://exceljet.net/formula/categorize-text-with-keywords
I'm trying to categorize certain products based on the beginning of each product name. My first table is the look-up table below:
My second table currently looks like this:
And I want the end result of that second table to look like this:
What excel formula can I use to achieve the red column? I've tried scouring the internet, for the formula that best suits my need, but I can't figure it out. I've seen people throw out the =Lookup(Search()) function, but my formula needs to start with the key word, but just contain the keyword somewhere in the cell.
I've read many different forums, but I haven't been able to find one that answers a scenario similar enough to mine. Any suggestions are appreciated.
If the first word of the Product Name is always matched to the product start, you can vlookup by just the 1st word. Assuming your product start is in column A, Categerization in Column B, Product Name in Column C, you can key in the formula in Column D:
'''
=vlookup(left(C2,search(" ",c2)-1),A:B,2,0)
'''
Just set your vlookup 4th parameter to TRUE:
Note: formula as written can be drag/filled down from B2. Also your Category Table needs to be in A-Z sorted order.
HTH

Vlookup function generating duplicate values, how can I fix this please?

Hy Every Body, I have two excel sheets name as "Blotter" and "Opportunity", I want to use "Vlookup" Function in Opportunity so that I can find out which opportunity is available in the blotter sheet. Please take a look at the Blotter sheet as under
In the Column B the Opportunities are available.
Now please look at the opportunity sheet.
In the opportunity sheet I am using this function.
=IF(D2 = "","",VLOOKUP(D2,blotter,10,0))
It working fine with first five rows but later it start duplicate the same value multiple time, because behind these cell on the blotter sheet the column B has Piad/place status instead of opportunity. So it duplicate the next opportunity. I have tried many tricks like match, index, but in vain.
I know it can be fixed. I have google it and also try to find it via youtube but unable to fix it.
I don't think it can be done without an intermediate column. The position of the next value in the lookup key depends on where the position of the last successful lookup was, so in a way the lookup chain is path dependent and I don't think you can build path dependency with any ease inside an Excel formula.
In the below example you get something akin to what I think you want by calculating how many spaces there are to the next valid lookup key in Column C, and then doing an Offset in column D. In column C I use an indirect which generates path dependency based on the sum of the cells above itself. You would need to apply similar principles to your example, should only need a single equivalent of my column C.
Formulas as follows:
Column C: =MATCH("OPP",INDIRECT("A"&SUM($C$1:C1)+2&":A50"),0)
Column D: =OFFSET($B$1,SUM($C$1:C2),0)

Excel countif does not look up a different sheet

I am hoping someone can help with this Excel 2016 issue. I have done extensive searching on the net and believe I have found the formula to address my requirements. Before sharing the formula, let me explain my need.
I am creating a budget spreadsheet. There is currently two sheets in the spreadsheet. sheet1 contains data for categories and keywords. Column A contains different categories like Car Fule, Salary, Bank Fee, etc. Column B contains keywords to be search for within the transaction description. An example could be:
car fule | Mobile
Sheet2 contains all the transaction data. All the columns other then column c isn't relevant for this issue. An example of a transaction description could be: "EXP mobile Hobbitville 2221 MiddleEarth".
I am trying to create a formula that does a search in the defined cell for column c, against the keywords found in sheet` column b. Then once a match is found, perform a indirect function call to give the category of the transaction. I cannot get the initial search to work.
Formula that should work is:
=countif(c2,"*"&sheet1!$b$1:$b$85&"*")
This always gives a value of 0 saying it hasn't been found. I am using ctrl shift enter and ctrl enter to make the an array formula. If I press f9, I get all the values defined from sheet 1 as {0, 0, ...} (or something like that) which is what I expect. In that array, I should get at least one element as a '1' (true value). If I can fix this part of the formula or find a better method, then I can build the rest of the formula. Any one with ideas?
This is the COUNTIF syntax,
COUNTIF(range, criteria)
It should be the other way around,
=COUNTIF(C:C,"*"&Sheet1!$B1&"*")
Let me know if its not working

Trying to use VLOOKUP for two Lookup Values

I have this formula:
=VLOOKUP(1910921,'All Training Raw Data'!A:C,2,FALSE)
The 1910921 refers to a training course but that training course has two ID's. The other being 01929831. I am looking to use the VLOOKUP function to find the email address of who has completed this course. How can I incorporate this second course ID into the VLOOKUP function?
Thanks
If I suppose that your first ID is in the column B and the second one in the column C and the e-mails in the column D, then you can do the following.
In the column A (the example is for A2) put the following formula :=CONCATENATE(B2,C2). Then change your VLOOKUP formula to include the additional ID and look for it in the column A, like this:
=VLOOKUP(191092101929831,'All Training Raw Data'!A:D,4,FALSE).
The other user's replies seem to be OK as long as you really need to do it with VLOOKUP function. Although, as I have already commented above I feel like it might not be the best option, as VLOOKUP always returns the value of the first match. Instead you could try using this formula.
=IF(MATCH($A1,$I$1:$I$2,0),&B1,"")
If you have the courses IDs on I:I column, you check if the course done by the user matches with any of them. If the condition is true, it will return the email from him, which I am guessing it is on the B:B column.
It worked for me so, adapt the ranges to your case and I hope it works for you too.

How to sumif the vlookup value of a range?

I'm not sure how to explain what I am trying to achieve so I will start with the data I am working with:
1) A table that lists IDs corresponding to Games. Each game has several IDs.
2) A table that lists IDs and $ Earned on those IDs.
In another table, I have the list of games and want to return the sum of $ Earned on those games:
Tables 1,2,3
I was trying to do this with a combination of a SUMIF and VLOOKUP formula but I can't seem to find a way to do that because the VLOOKUP returns a value rather than a range. What I want to do is sum a sum_range ($ earned) if the lookup value of the range (game corresponding to the code) is a match.
I could simply add a column to the second table that returns the game of that code with a VLOOKUP. But the problem is that this would need to be done in a very large number of sheets, and with each time the new data is received.
Hopefully that made sense and thank you in advance for any help I can get!
Cheers,
Maria
Well this may be a bit of a cheat. if you look at your game code, you are either looking for basketball or baseball. So we could do a sum if the code contains one of those words.
If case sensitivity is important
=SUMPRODUCT(--(ISNUMBER(FIND("Basketball",B2:B16)))*C2:C16)
or if case sensitivity is not important
=SUMPRODUCT(--(ISNUMBER(SEARCH("Basketball",B2:B16)))*C2:C16)
B2:B16 would be your code in table 2
C2:C16 would be your $ earned column in C2
The formula would be placed where the ? cell is beside big win Basketball.
updated option for keyword
So if you are not looking for just baseball or basketball, but the entire string of the key words that you are looking for the total for, you could use the following provided the words in table three form part of the code when the spaces are removed.
=SUMPRODUCT(--(ISNUMBER(FIND(SUBSTITUTE(B19," ",""),B2:B16)))*C2:C16)
or
=SUMPRODUCT(--(ISNUMBER(SEARCH(SUBSTITUTE(B19," ",""),B2:B16)))*C2:C16)
This assumes the keyword your are looking for in the code is in B19. The substitute function removes the spaces to match your code.
In the second table add a (hidden) column, where you perform a VLOOKUP in the first table of the Code, retrieving the Game name.
Now you have something to base your SUMIF on: the value in the additional, hidden column should match the Game you have in your summary.

Resources