Multiple vlookups in one cell - excel

Ok I have two vlookups that both search from the same array but with different criterias.The first vlookup would search for the Price category. The second vlookup would seek the type of product.
This is an example array:
ID Price Type
1 Banana Fruit
2 Apple Fruit
3 Orange Fruit
4 Corn Flakes Cereal
5 Monster Energy Drink
The syntax would be:
Search for the first vlookup, if there is no results, try to search for the second vlookup.
If the first or second vlookup is true, then return value ID.
I have already made the vlookups but I have no idea how to combine both in one cell
Edit: Vlookups
=Vlookup(A2,E4:G8,2,0)
=Vlookup(B2,E4:G8,2,0)
And the lists:
A column B column
List 1 List 2
Banana Hardware
Carrot Vegetable
Orange Chocolate
Mango Candy
Fruit

It may be as simple as this:
=IFERROR(Vlookup(A2,E4:G8,2,0),Vlookup(B2,E4:G8,2,0))
Try to find one, if it fails try the other.

This formula returns corressponding ID if found value from A2 or B2 in ranges F4:F8 or G4:G8 respectively, or "not found in both columns" if both values not found:
=IFERROR(INDEX(E4:E8,IFERROR(MATCH(A2,F4:F8,0),MATCH(B2,G4:G8,0))),"not found in both columns")

Related

How to retrieve Top 2 rows from each group in excel sheet?

The problem is simple to understand. I just need to know a formula that will help find a way to fetch the top 2 rows of each group in an excel sheet.
The below example is grouped by column 1.
Example
Given Table:
Column 1
Column 2
Apple
A102012
Apple
A102013
Apple
A102014
Banana
A102015
Banana
A102016
Banana
A102017
Coconut
A102017
Result:
Column 1
Column 2
Apple
A102012
Apple
A102013
Banana
A102015
Banana
A102016
Coconut
A102017
Try:
Formula in D1:
=REDUCE(A1:B1,UNIQUE(A2:A8),LAMBDA(a,b,VSTACK(a,TAKE(FILTER(A2:B8,A2:A8=b),2))))
To mimic this for Google Sheets:
=REDUCE(A1:B1,UNIQUE(A2:A8),LAMBDA(a,b,{a;QUERY(A2:B8,"Where A='"&b&"' limit 2")}))
A much slower alternative is:
=FILTER(A:B,INDEX(COUNTIFS(A:A,A:A,ROW(A:A),"<="&ROW(A:A)))<3)
A faster method than countifs not using most recent additions to Excel, if it can be assumed that data are pre-sorted:
=LET(count,COUNTA(A:A),Column1,A2:INDEX(A:A,count),Column12,A2:INDEX(B:B,count),FILTER(Column12,SCAN(0,SEQUENCE(count-1),LAMBDA(a,c,IF(c=1,1,IF(INDEX(Column1,c)=INDEX(Column1,c-1),a+1,1))))<=2))
or in Google Sheets:
=ArrayFormula(lambda(Column12,filter(Column12,SCAN(0,SEQUENCE(rows(Column12)),LAMBDA(a,c,IF(c=1,1,IF(INDEX(Column12,c,1)=INDEX(Column12,c-1,1),a+1,1))))<=2))(filter(A2:B,A2:A<>"")))
If you have Excel 365 you can also use this formula
=LET(rank,MAP(tblData[value],tblData[fruit],
LAMBDA(v,f,SUMPRODUCT((tblData[fruit]=f)*(v<tblData[value]))+1)),
FILTER(tblData,rank<=2))
The MAP function calculates the rank of each row within its group.
Then we can filter by that list.

Excel: Grouping and restructuring data in Excel

In Excel, I want to convert the table on the top (Initial data) into the one at the bottom (Desired output).
I want to group the items in the second row by the first row, and then generate one column per unique value of the first row and list the items of the corresponding group in that column.
Is there a way to do that without manually copying cells?
Table: Initial data
Fruit
Banana
Fruit
Apple
Fruit
Grape
Vegetable
Spinach
Vegetable
Eggplant
Table: Desired output
Fruit
Vegetable
Banane
Spinach
Apple
Eggplant
Grape
If you have access to the UNIQUE and FILTER functions (Excel 365), you could accomplish this as follows.
Assuming your data is in A1:B5. In D1 enter:
=TRANSPOSE(UNIQUE($A$1:$A$5))
This will get you the unique values from the cells in A in D1:E1. Then in D2 enter:
=FILTER($B$1:$B$5,$A$1:$A$5=D1)
And drag to the right.
I.e. you do this:
Result:

How to populate columns with data in Excel using unique row combinations between two columns

This seems like it should be easy enough to do, but I can't seem to figure it out or find a tutorial.
I have two columns containing values. I would like the unique column combinations to repeat in another set of columns, and count the instances.
COLUMN A COLUMN B COLUMN C COLUMN D COLUMN E
John Apples John Apples 2
John Apples John Bananas 1
John Bananas Sara Apples 1
Sara Apples Sara Kiwi 1
Sara Kiwi Mike Carrots 2
Mike Carrots Mike Kiwi 1
Mike Carrots Apples 2
Mike Kiwi Carrots 1
Apples Kiwi 1
Apples
Carrots
Kiwi
I was able to transfer the unique values from one column to another using INDEX and MATCH, but can't get it to work with two columns.
This tutorial shows what I am looking for, but I'd like the second set of data to stay in a column, and not transpose into rows. https://www.extendoffice.com/documents/excel/3358-excel-transpose-unique-values.html
Try following this short animated screen capture finishing with the following formula in E2.
=COUNTIFS(A:A, IF(LEN(C2), C2, ""), B:B, D2)
What you describe is called a Pivot Table. Drag Name and Fruit into the rows area and Fruit again into the Values area to have it counted. Pivot tables can have different layouts, i.e. with repeating labels, or in compact format.

Count number of rows where value in a column is not a part of a list

I have a data set, let's say like this:
Item Name
Apple
Carrot
Carrot
Pear
Pear
Pineapple
Radish
Orange
Orange
Pineapple
Pineapple
and I also have a LIST like this:
List of Items:
Apple
Orange
Pineapple
How to write a formula that will count how many rows in the dataset have a value that is NOT a part of the list? ... so in this case 5...
You could just take the number which are in the list away from the total:-
=COUNTA($A$2:$A$20)-SUMPRODUCT(COUNTIF($A$2:$A$20,$B$2:$B$20))
assuming data items in column A and list in column B.
You need to create a named range of the list.
Mark your list of items and in the "name box" write LIST.
Now if the long list is in column A, then in column B write the following formula:
=IFERROR(VLOOKUP(A1;LIST;1;FALSE);1)
It will find the match in the LIST if it excists, if not write "1".
=COUNTIFS(rng,"<>Apple",rng,"<>Orange",rng,"<>Pineapple")
Assuming your named range for the long column is rng.
Obviously this works best if your short list is very short.

miss and match on excel

I'm not even sure if what i want to happen is possible but here it is :
So i have a list on column A and another on column B. Say, column A has apples, bananas, eggs... Then column B has apple pies, banana pies, egg pies...on column C, I want excel to tell me that apples and apple pies match and bananas and banana pies match, and so on. Then tell me if they don't match at all. I want it so that even if i want 2 values from column A to match with a value in column B. For example aside from apples there could also be pears in column A but i would still want pears to return a match value with apple pies. I hope this is not too confusing
... Thanks in advance!
Ok, I am going to give you multiple answers because I am not sure what the question is. If Gary's Student's comment is the right answer and you just want to match the contents then all you need to do is put this in C2 and copy it to every row:
=IF(ISERROR(FIND(A2,B2)),"no match","match")
But if your comment about 1-2=bad, 3-8=good and 9-10=very good is what you really want then all you need to do is put this in C2 and copy it to every row:
=IF(B2=CHOOSE(A2,"bad","bad","good","good","good","good","good","good","very good","very good"),"match","no match")
What that does is change the number in column A to be the equivalent string and then match that string against column B.
But if you are looking for a solution that works for both things then you need a dictionary. If you use ALL the piossible values from B as the keys and each matching value from A as the values then you can call MATCH twice and see if the value belongs to the key.
So for example the dictionary for the pie example might look like this (notice that pies can have more than one ingredient):
E F G H I J K
1 Key Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
2 lemon pie lemon egg
3 apple pie apple pear
4 pear pie pear
5 egg pie egg
And the dictionary for the bad and good example would look like:
E F G H I J K
1 Key Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
2 bad 1 2
3 good 3 4 5 6 7 8
4 very good 9 10
Then you can stick this in C2 and copy it to every row:
=IF(ISNA(MATCH(A2,OFFSET(F$1:O$1,MATCH(B2,E$2:E$20,0),0),0)),"no match","match")
What this does is look up the value in column B in the dictionary and find what row it is in. Then it offsets F$1:O$1 by that many rows so that the range for the outside match is the correct list of incgredients. Then it matches the value in column A by the list of ingredients that the offseted inside match produced.
Maybe some screenshots will help:

Resources