VLOOKUP with multiple criterias in different columns [duplicate] - excel

This question already has answers here:
Vlookup using 2 columns to reference another
(2 answers)
Closed 3 years ago.
I have the following Excel spreadsheet:
A B C D E
1 Products Brands Revenue Search Criterias
2 Product A Brand1 500 Criteria 1: Product C
3 Product B Brand3 800 Criteria 2: Brand 3
4 Product B Brand2 900 Revenue: 300
5 Product C Brand1 200
6 Product C Brand3 300
7 Product C Brand4 750
8 Product D Brand1 450
9 Product C Brand4 150
10
As you can see in Column A I have list of products and in Column B the corresponding brands and in Column C the revenue.
Now I want to use VLOOKUP to search for the revenue based on a product (Cell E2) and a brand (Cell E3). Therefore, I tried to go with this formula:
E4 =VLOOKUP(E2&"-"&E3,A1:C9,3,FALSE)
However, this formula gives me #NV.
What do I need to change in my formula to make it work?
Please note:
I know I could solve this issue by adding a helper column in which I combine the datas from Column A and Column B and then let the VLOOKUP run over this helper column. However, I am looking for a solution without this helper column.

First of all, please note that your lookup array does not have a space while your lookup value does! That will never return a match, so address that issue first.
Furthermore, I would highly recommend to not concatenate values in a multi-criteria lookup, ever! That's very error prone. Instead use boolean logic to create an array of 1's and 0's to use the powerfull combination of INDEX and MATCH. Try to get into the habit of using that combination over VLOOKUP if you are a regular user of Excel and it's worksheet functions.
Here is a small introduction to this combination of functions. And as mentioned in that post too, INDEX will come in handy much more often as you will notice in the below example when we create our return array. This will prevent the use of having to enter as an array formula through CtrlShiftEnter =)
Formula in E4:
=INDEX(C2:C9,MATCH(1,INDEX((A2:A9=E2)*(B2:B9=E3),),0))
When you actually got numeric values under Revenue you can simply use SUMIFS, as the other answer suggest.

I would strongly recommend using SUMIFS instead of VLOOKUP because this would make sure if you have multiple same values it will add them together:
=SUMIFS(C:C,A:A,E2,B:B,E3)
But this function will only work in newer versions of Excel if you need it for an older version of excel you need to work with SUMPRODUCT
Optional you can also use an alternative VLOOKUP which would be a combination of INDEX and MATCH. There are two options, either the array formula with the "{}" can in some cases result to wrong data, but is easy to understand:
{=INDEX(C:C,MATCH(E2&E3,A:A&B:B,0))}
This is a matricial formula so the "{}" are added by Excel when you type the formula regularly by pressing CTRL + SHIFT + ENTER
otherwise use. I would always recomend using regular formulas over matricial formulas
Quote user JvdV
Formula in E4:
=INDEX(C2:C9,MATCH(1,INDEX((A2:A9=E2)*(B2:B9=E3),),0))

The shortest and fastest formula for 2 criteria Lookup is using DGET()
Table layout as below :
A B C D E F
1 Products Brands Revenue Search Criterias
2 Product A Brand1 500 Products Brands Revenue
3 Product B Brand3 800 Product C Brand3
4 Product B Brand2 900
5 Product C Brand1 200
6 Product C Brand3 300
7 Product C Brand4 750
8 Product D Brand1 450
9 Product C Brand4 150
Formula in F3 :
=DGET(A1:C9,F2,D2:E3)
and, will return the desired result : 300

Related

Sum values using lookup table, where lookup values are a list of values with comma delimiter

I am trying to sum values based that equal a lookup value. However, that value is actually a list of values delimited by a comma. Below is an example of what I mean.
Suppose I have raw data in the form of sheet1 below:
Sheet1:
A
B
1
ID
VALUE
2
A
30
3
A
50
4
A
20
5
B
10
6
B
20
7
C
70
8
C
40
9
D
30
10
E
50
11
F
20
12
F
30
13
G
10
And I have a look table that groups all IDs by their respective teams, as per sheet2 below.
Sheet2:
A
B
1
TEAM
IDS
2
Red
A, B
3
Blue
C, D
4
Green
E, F, G
And I want to create a report where the user can select the team name, and the sum of the values in sheet1 will aggregate based on the selection, as per the following example. So the user would select "Green" in cell B1 and it would return the sum of values that correspond to E, F, and G in sheet1.
Report:
A
B
1
Select Team:
Green
2
Sum:
110
I have searched all over for a solution to this and was able to find something similar. I tried to repurpose the formula for my data but couldn't get it to work because I think that solution dealt with numbers rather than text.
Excel: Perform a SUMIF where the criteria is a comma-delimited list
Any suggestions would be greatly appreciated!
Edit: Just want to add that I realize I could first parse out the IDs in sheet2, however I'm looking for a formula that can bypass that as my real dataset is quite large and parsing out the IDs under each team would explode the number of rows.
A variation of #JvdV solution on the linked question:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,FILTERXML("<t><s>"&SUBSTITUTE(VLOOKUP(Sheet2!F1,Sheet2!A:B,2,FALSE),",","</s><s>")&"</s></t>","//s")))
Note, this only works with Excel 2013 or later and only on PC. FILTERXML is not available on Mac or prior to 2013.
If Mac or prior to 2013:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,TRIM(MID(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",REPT(" ",999)),(ROW($ZY1:INDEX($ZY:$ZY,LEN(VLOOKUP(F1,Sheet2!A:B,2,FALSE))-LEN(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",""))+1))-1)*999+1,999))))

Ignore text values in subtotal function

Excel-Sheet:
A B C D E
1 1.200
2 Product A 500
3 Product B 400
4 Product C OK
5 Product D #NA
6 Product E 300
7
8
In the above table I have list of products in Column A and some data about the products in Column B.
In Cell B1 I want to calculated the subtotal of Column B using =SUBTOTAL(9,B2:B6).
However, now I have the issue that Column B not only consists of numbers.
It can also have the data type text (OK, NA). Therefore, the result in Cell B1 currently is #NA.
Is there any kind of formula that I could use so only the number data is considered and the result is 1.200 as in the table above?
Please note:
This function =AGGREGATE(9,6,B2:B6) won't help me because I want to filter the list later on so I need to go with the SUBTOTAL.
Use 7 as the second criterion in AGGREGATE instead of 6 as it will also exclude hidden rows:
=AGGREGATE(9,7,B2:B6)
You can solve this, combining the Excel worksheet functions =Value() and =IfERROR():
The function =Value() gives the value of a number, and in case of text it gives an error.
=IfError() can be used to give 0 in that case.
So, imagine you have following situation:
Column A Column B Column C
1 =Value(A1) =IfError(B1;0)
3.5 =Value(A2) =IfError(B2;0)
AB =Value(A3) =IfError(B3;0)
abc10 =Value(A4) =IfError(B4;0)
This gives following results:
Column A Column B Column C
1 1 1
3.5 3.5 3.5
AB #Value 0
abc10 #Value 0
You can simply take the sum of column C.
So this is based on the summary in B1.
=SUM(IF(ISERROR(B2:B6),"",B2:B6))
You need to push Ctrl+Shft+Enter for this to work.
Hope it helps.

SUMIFS with mutliple OR/AND criterias (using a cell reference)

A B C D E F G E
1 Products Suppliers Value Criteria 1: Product_C Result: 600
2 Product_A Supplier_01 500 Criteria 2: Supplier_01
3 Product_B Supplier_01 600 Criteria 3: Supplier_03
4 Product_B Supplier_02 300
5 Product_C Supplier_01 200
6 Product_C Supplier_01 400
7 Product_C Supplier_03 800
8
9
In the table you find a list of different Products (Column A) and Suppliers (Column B).
In Cell G1 I want to get the sum of the values in Column C if the following conditions are met:
Product = Product_C AND
Supplier = Supplier_01 OR Supplier_03
Those conditions are typed in as Criteria 1-3 in Cells E1:E3.
In order to achieve this I tried to go with the solution from these questions (Q1,Q2) which gives me the correct result:
G1 =SUM(SUMIFS($C:$C,$A:$A,$E$1,$B:$B,{"Supplier_01","Supplier_02"}))
However, my issue with this solution is that I need to enter the OR-criterias manually as {"Supplier_01","Supplier_02"}. How do I have to change my formula so I can refer to the values in Cells E2:E3 so if the user changes those values the result is automatically adjusted?
One possibility:
=SUMPRODUCT((A2:A7=E1)*((B2:B7=E2)+(B2:B7=E3))*C2:C7)
It will be easy to extend criteria in the same fashion for both column A and B.
I was going to say that you need to transpose E2:E3. I think this is true in general, but in this particular case with only a single criterion applying to column A, you don't need to:
=SUM(SUMIFS($C:$C,$A:$A,$E$1,$B:$B,$E$2:$E$3))
works if entered as an array formula.
If you have multiple criteria for A and B, you do need to transpose one set of criteria:
=SUM(SUMIFS($C:$C,$A:$A,$E$1:$E$2,$B:$B,TRANSPOSE($E$3:$E$4)))
try this
=SUM(SUMIFS($C:$C,$A:$A,$E$1,$B:$B,E2:E3))
or
=SUM(IF(($A$2:$A$7=E1)*(($B$2:$B$7=E2)+($B$2:$B$7=E3)),$C$2:$C$7,0))

VLOOKUP if only a part of the search criteria matches with the values in the table

I have the following Excel spreadsheet:
A B C
1 List Search Criteria Result
2 2019-01 9 2019-09
3 2019-02
4 2019-03
5 2019-04
6 2019-05
7 2019-06
8 2019-07
9 2019-08
10 2019-09
11 2019-12
12
In Column A I have a list of all months in 2019. In Cell B2 I want to search for a month by just enterring in the number of the month. The result should appear in Cell C2. Therefore, I tried to go with the following formula in Cell C2:
C2 =VLOOKUP(B2,$A$2:$A$13,1,FALSE)
The issue is now that basically my search criteria is not 2019-09. It is just 9 and therefore the VLOOKUP is not able to find it within Column A.
So far I came up with the following solutions to solve this issue:
a) Change the search criteria to ="2019-"&B2.
b) Add a helper column next to Column A in which I only dsiplay the number of the months
However, I am wondering if there is smarter solution which does the job within the VLOOKUP function directly (maybe a combination with the MID function)?
Based on the comments below the question there are two solutions to solve the problem:
Option A)
If the year in the list does not change and will be the same you can go with this formula:
=VLOOKUP(TEXT(B2,"\*00"),$A$2:$A$13,1,FALSE)
Option B)
If the year in the list changes you can go with this formula and edit the first parameter accordingly:
=VLOOKUP("2019-"&TEXT(B2,"00"),$A$2:$A$13,1,FALSE)

Getting the next higher value with VLOOKUP or INDEX/MATCH

I have the following Excel spreadsheet:
A B C D
1 0 Product 1 7.500 Product 4
2 1.000 Product 2
3 5.000 Product 3
4 10.000 Product 4
5
In Cell C1 I type a random number (in this case 7.500). Now I want that in Cell D1 the corresponding Product is shown to the value in Cell C1. Since 7.500 does not exist in Column A the next higher value should be used. In this case 10.000 which belongs to Product 4.
I tried to go with the following formula in Cell D2 but instead of getting Product 4 I get #NV as a result.
=INDEX(A1:B4;MATCH(C1;A1:A4;-1);2)
The only solution I found so far was changing the values in Column A from ascending to descending. However, I would prefer to have a solution which does not require a change of the order in the list.
Do you have any idea how to solve this issue without changing the order in the list?
For unsorted data you can use below formula::
=INDEX(B1:B4,MATCH(SMALL($A$1:$A$4,COUNTIF($A$1:$A$4,"<"&C1)+1),A1:A4,0))
See image for reference

Resources