I thought lookup function will return next largest value.
In the case below, it returns 100.
Should it return 1 because -1 is bigger than -100?
=-LOOKUP(, {-1;-100})
Hi ,
Let us start with the following formula :
=LOOKUP(
100000,
0+RIGHT(D2,
ROW($1:$255)))
The crucial elements are the three which have been colored.
1. 100000 - When you use the LOOKUP function with a first parameter which is larger in value than any value which can occur within the array ( the second parameter ) , it returns the last element of the array.
2. 0 + ...... This converts all the values which are formed by the array RIGHT function in conjunction with the ROW function , into numbers.
3. ROW($1:$255) ..... This returns an array of numbers from 1 through 255.
When we take the RIGHT function and the ROW function together , and use it on the following data :
ABC 05-11 = 10,798.00
XYZ 05-12 = 10,416.00
QWER 05-12 = 10,416.66
we get an array of values , as follows :
{6;66;0.66;6.66;16.66;416.66;#VALUE!;#VALUE!;10416.66;10416.66;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!......}
What is happening here is that the last digit of the data item is the first element of the above array ; the last 2 digits of the data item are the second element of the above array.
When we come to the comma , the value ,416.66 is not a valid number , and hence it results in a #VALUE! error value.
The next part of the data item , which is 0,416.66 is again not a valid number , and hence it also results in a #VALUE! error value.
When we get to 10,416.66 , we have a valid number again.
All the values to the left of the = sign thereafter result in #VALUE! error values.
Since the LOOKUP function ignores error values , the last valid numeric value which is smaller than 100000 is 10,416.66
----------------------------------------------------------------------------------
If we wish to avoid the use of the 100000 , and the 0+ , we need to do two things :
1. Convert the numbers to negative numbers by prefixing the RIGHT function with the minus sign -.
2. Omit the 100000 since we are no longer looking at positive values. Omitting the first parameter is the same as using 0.
Since all negative numbers will be smaller than 0 i.e. since 0 will be bigger than all negative numbers , the LOOKUP function will still return the last number.
However , because we converted all numbers in the array to negative numbers , we need to now use another minus sign before the overall formula to convert the returned negative number back to a positive number.
Hence :
=-LOOKUP(,-RIGHT(D2,ROW($1:$255)))
Narayan