Hello,
I'm trying to solve this bit of function problem.
I'm trying to use vlookup function in table 2 referencing table 1 using the approximate parameter. However, an approximate vlookup value is by definition the closest *least* value. Is there a trigger of some sort to locate the closest *greatest* value as well?
For instance, if the lookup_value in table 2 is 2.450 but the referenced table 1 only has 2.445 and 2.475, I will only retrieve the respective value related to 2.445 -- how would I retrieve the other value at 2.475?
Essentially, if a lookup_value rests in between two values of whatever is being referenced, I am trying to average those two closest numbers. Is there a function I've overlooked that may help with this?
Thanks...
Last edited by Lohkee; 11-16-2009 at 09:08 PM.
I suppose if you can create a duplicate lookup table, only in the second one sort descending, you can set the fourth VLOOKUP parameter to -1, which I think will do what you're looking for.
If your table is A1:A10 sorted ascending then with lookup value in C1 this will give the nearest "lower" value
=LOOKUP(C1,A1:A10)
for the higher value either
=INDEX(A1:A10,MATCH(C1,A1:A10)+(LOOKUP(C1,A1:A10)<>C1))
or this array formula (which doesn't need A1:A10 sorted)
=MIN(IF(A1:A10>=C1,A1:A10))
confirmed with CTRL+SHIFT+ENTER
VLOOKUP doesn't play as nicely, but I have a formula I use that does this, a mixing of INDEX/MATCH plus a standard lookup.
Since you're trying to use fuzzy match on a VLOOKUP, I can safely assume the data is already sorted.
In this example, the "match" value H3 is "MATCHED", and then the result is incremented by 1 if it isn't an exact match. Then value from column B is returned for the answer.
=INDEX($B$2:$B$8, MATCH(H3,$A$2:$A$8,1) + (LOOKUP(H3,$A$2:$A$8) < H3))
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Hi, with Vlookup this will be tricky. But you could use Index/Match instead.
You need to sort your lookup table in descending order, then use
=INDEX(lookup_table,MATCH(lookup_value,lookup_column,-1),column)
Using the -1 as the last argument, Match will find the next greatest value, but the lookup_range must be sorted descending. Also, make sure that Match looks only in the column, don't give it the whole table.
hope that was not too convoluted...
teylyn
Microsoft MVP - Excel
At Excelforum, you can say "Thank you!" by clicking theicon below the post.
Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.
I'm still having trouble wrapping my mind around these functions for a higher value.
If I have the following:
A / B / C / D
2.445 / 312 / 2.450 / = functions
2.470 / 345 / ---- / -----
=LOOKUP(C1,A1:B2) will give me 312, as expected.
However, the =INDEX(... suggestion doesn't seem to work. Basically, yes, I am trying to go down one extra cell to B2 and retrieve 345, at which point I can average the two.
Very new to formulas so the index/match is difficult for me to understand.
Thank you for such fast replies!
Also, in regards to descending order:
Column B is already a function referencing other cells and does not have the $ signs -- how would I be able to create a duplicate without redoing each cell?
Last edited by Lohkee; 11-16-2009 at 08:46 PM.
As I said above, for the Index/Match function to work with the last Match parameter being -1, the lookup table must be in descending order.
It can take a wee while to internalise Index/Match. You're not alone![]()
teylyn
Microsoft MVP - Excel
At Excelforum, you can say "Thank you!" by clicking theicon below the post.
Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.
Edited last post regarding descending order.
I'm getting a bit lost now. Could you possibly upload a small data sample in a workbook. That'll be a lot easier to follow.
You can upload a file by clicking "Go Advanced" below and then the paper clip icon.
teylyn
Microsoft MVP - Excel
At Excelforum, you can say "Thank you!" by clicking theicon below the post.
Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.
Without changing the order....you can use a version of the formula I posted above. It will match C1 with the first value that's equal to or greater than C1 and return the corresponding value in B1:B10
=INDEX(B1:B10,MATCH(C1,A1:A10)+(LOOKUP(C1,A1:A10)<>C1))
......or why not skip the intermediate steps....
This formula will give you the average directly...
=AVERAGE(OFFSET(B1,MATCH(C1,A1:A10)-1,,2))
For instance, column A is simply a set of numbers. B1 is =D7 and B2 is =D8. Column B cannot be resorted unless I use $. Unclear how to resort A and B without changing the cells to include $.
daddylonglegs: this gives me a #N/A as before...
Edit:
Ooh, that averge formula looks promising..
Excellent ! The average formula with offset and match is exactly what I needed. Thank you kindly. Now to research how these are used so I don't have to ask again :D
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks