Please consider the table below:
If we write VLOOKUP(12,A1:B6,2,TRUE) we will get 2 as a result since the lookup value will match with 10 in the first column of the array and return the corresponding value in the second column.
What I am looking for is somewhat different. I want to find the value corresponding to the next greater value. For example, when my lookup value of 12, it will now match with 15
in the first column and then return 3 from the second column.
How do I do this preferably with VLOOKUP function?
If you have Excel O365 with the FILTER function, and if your lookup value is in D1, you can use:
=MIN(FILTER(B1:B5,A1:A5>=D1))
If the entries in column B are text, and not sorted numeric, you can use:
=INDEX(FILTER(B1:B5,A1:A5>=D1),1)
If you do not have O365 available then you can use the INDEX/MATCH functions entered as array formula:
=INDEX($B$1:$B$6,MATCH(TRUE,$A$1:$A$6>12,0))
Array formula after editing is confirmed by pressing ctrl + shift + enter
Related
I've the following table:
In cell A7 I define the index of column 1 I want to use for my computation, in this case A. For every row with index A I want to multiple the value for that row of column 2 with column 3. In this example there are two rows with index A, so I want to do the computation for both rows and then add the results. That will look as follows: 5 * 3 + 9 * 7= 78.
To achieve this, I first tried to write a code that sums all values in column 2 that match a given index. That index is A, so 5 + 9= 14 is what the output should be. I only get my code to find the first match, so that's row 2 and it will display the value of column 2, so that's 5. This is my code for cell B7:
=SUM(INDEX(B2:B5;MATCH(A7;A2:A5;0)))
Even if I solve this I still don't have what I actually want, but I think it's a start. How do I get what I innitially wanted and have the outcome equal 78?
Type in this formula:
=SUM((A2:A5=A7)*(B2:B5)*(C2:C5))
Then Ctrl-Shift-Enter
This converts it into an array formula, which you can identify because there will be braces around it:
{=SUM((A2:A5=A7)*(B2:B5)*(C2:C5))}
Using BYROW()
• Formula used in cell B7
=SUM(BYROW(FILTER(Table12[[Column 2]:[Column 3]],A7=Table12[Column 1]),LAMBDA(m,PRODUCT(m))))
If not using Structured References then
=SUM(BYROW(FILTER(B2:C5,A7=A2:A5),LAMBDA(m,PRODUCT(m))))
Or, use the incredible & versatile SUMPRODUCT() Function
• Formula used in cell C7
=SUMPRODUCT((A7=A2:A5)*(B2:B5)*(C2:C5))
I need to check if a value from column E is between any pair of values in A:B and if so, return a letter from column C. Desired result is in F column.
I think an Array formula using Match() to get the row on which the hit is found that is then passed to INDEX() may solve this:
=INDEX(C:C,MATCH(1,(E3>=A:A)*(E3<=B:B),0))
That's an Array formula (CSE Formula) so you'll have to Ctrl+Shift+Enter it so it gets the squirrelly brackets.
If you have a value that falls into more than one range, this will return the first row too, which is a nice feature.
I need to be able to find the row number of the row where matching criteria from A1 is equal or greater than values in column C and lesser or equal than values in column D
I can use INDEX and MATCH combo but not sure if this is something I should use for multiple criteria matching.
Any help or suggestions are highly appreciated.
I would not use MATCH to get the row number since you have multiple criteria. I would still use INDEX however to get the value of the row in E once the proper row number was discovered.
So instead of MATCH I would use an array formula using an IF statement that contained multiple criteria. Now note that array formulas need to be entered using ctrl + shift + enter. The IF statement would look like this:
=IF((A1>=C:C)*(A1<=D:D),ROW(A:A),"")
Note: I did not use the AND formula here because that cannot take in arrays. But since booleans are just 1's or 0's in Excel, multiplying the criteria works just fine.
This now gives us an array containing only blanks and valid row numbers. Such that if rows 5 and 7 were both valid the array would look like:
{"","","","",5,"",7,"",...}
Now if we encapsulate that IF statement with a SMALL we can get whatever valid row we want. In this case since we just want the first valid row we can use:
=SMALL(IF((A1>=C:C)*(A1<=D:D),ROW(A:A),""),1)
Which if the first valid row is 5 then that will return 5. Incrementing the K value of the SMALL formula will allow you to grab the 2nd, 3rd, etc valid row.
Now of course since we have the row number a simple INDEX will get us the value in column E:
=INDEX(E:E,SMALL(IF((A1>=C:C)*(A1<=D:D),ROW(A:A),""),1))
If you need to match more than one column value to retrieve a row number, that is, if two or more columns together create a unique ID you can use an array formula with MATCH as below:
MATCH(1,(A:A=J1)*(B:B=K1)*(C:C=L1),0)
where A, B, C contain the column array to be matched to retrieve the unique row number corresponding to the value in J1, K1, L1 respectively.
For a step-by-step guide, Christian Pedersen's Explainer
A B
5 25
4 10
3 15
5 100
in this case i want to vlookup the "5" from column A & answer would be 100
=+VLOOKUP("5",A:B,2,FALSE)
which give me 25
Use array formulas. For example, assuming your numbers above are in A2:B5, type the following within a single cell, and press Ctrl + Shift + Enter:
=MAX(IF(A2:A5=5,B2:B5,-1000000))
VLOOKUP only allows you to lookup the first occurence.
Your best option is to filter the table used for VLOOKUP to order from largest to smallest based on that second column. This will force the first instance of lookup_value in VLOOKUP to be next to the highest value of that entry. The below duplicates of lookup_value all have lower column two values and hence will not be seen by VLOOKUP as the highest entries are pushed to the top.
We can use this also
=SUMPRODUCT((LARGE(IF(A2:A5=5,B2:B5,""),1)))
Press Ctrl + Shift + Enter.
I am newbie to excel. I have this following data in excel sheet.
I want to have the value of G11 returned 27, as the value of its corresponding cell in column D, which is D11 matches to E8, and E9, which then correspond to the values of 14 and 27 in column J. Could someone tell me how to return a match value when I have two match situations and I need the maximum one. I am using the following formula.
=IF(D11=1,0,INDEX($H$4:$H$13,MATCH(D11,$E$4:$E$13,0),1))
I know if I use
=IF(D11=1,0,INDEX($H$4:$H$13,MATCH(D11,$E$4:$E$13,0)+1,1))
it returns me with the value 27 or greater of the both values but it will not work if I have three values and I want the maximum.
This will do it confirmed with ctrl+shift+enter:
{=MAX(IF(E4:E13=D11,J4:J13))}
Curly braces should not be entered manually, be sure to confirm with ctrl+shift+enter
This says:
Look for rows where the value in E matches D11
If you find one, return the value in column J
Give the maximum value of the result you find
This will cause errors if there are no matches. You also probably are designing your sheet in a not ideal way.
You can use the formula:
=IF(D11=1,0,MAX(IF(D11=$E$4:$E$13,$H$4:$H$13,0)))
entered as an array formula (i.e. you press Ctrl+Shift+Enter instead of Enter alone) for G11.
MATCH returns the first match, so that's why I'm using another IF instead.