r/excel•
nipnotoad

Lookup specific value

solved

I am using the formula =LOOKUP(B2-1,$B$2:B2,$C$2:C2) to lookup the value on it's parent level (I.E. level 2 lookup results value of next level 1 above). The formula doesn't work when there's duplicate values as shown below on ID 8. I am trying to get the lookup value on ID 8 to show the value on ID 7, but it's showing the value on ID 3 (which are both level 2). Is there a way to set the lookup to pull the "closest" in reference to cell location? Or any other way to get the correct value.

IDlevelvalueresult from my lookup formulaexpected lookup return value
111#n/a (formula =LOOKUP(B2-1,$B$2:B2,$C$2:C2) )#n/a
22211 (value on ID 1)
32211 (value on ID 1)
43422 (value on ID 3)
54544 (value on ID 4)
63222 (value on ID 3)
72111 (value on ID 1)
8322 (want lookup value from ID 7; looking up the value from ID 3)1 (value on ID 7)
92211 (value on ID 1)

​

Posted Mar 11, 2019, 8:50 PM UTC

33
finickyone942•

There’s probably a lot of detail to get into here, but the short version is that any function performing an approximate match (which LOOKUP is only capable of doing) will probably not return any logical results over unsorted data.* Your data in B is not sorted.

Try

=LOOKUP(2,1/(B$2:B2=(B2-1)),C$2:C2)

This also does not provide sorted data, but rather an array of 1s (where B=(B2-1)) and errors (where B<>(B2–1)) to which searching for 2 provides the last 1, so the last matching record. You’ll get a #DIV/0! instead of your N/A! for the first record; if that’s a real crisis you can IFERROR(...,errortext) the formula and provide something else.

Note: *there is, of course, a logic underneath the results provided by an approximate match over unsorted data, but it’s not something I can explain succinctly.

3
nipnotoadOP•

Solution Verified

2
Clippy_Office_AsstMOD•

You have awarded 1 point to finickyone

^I ^am ^a ^bot, ^please ^contact ^the ^mods ^for ^any ^questions.

1
[deleted]•

[deleted]

1