I'm building a simple POS to calculate item cost. I'm able to calculate item cost for Belts and Scarf but when i calculate item cost for jewellery
it return the wrong calculating.
The formula i'm using = B37 * VLOOKUP(B36, A2:B5, 2, TRUE)
Your items aren't sorted. You must sort items (A3:A5) A to Z.
Changing TRUE to FALSE changes the way VLOOKUP works:
If TRUE or omitted, an exact or approximate match is returned. If an
exact match is not found, the next largest value that is less than
lookup_value is returned. The values in the first column of
table_array must be placed in ascending sort order; otherwise, VLOOKUP
may not give the correct value. For more information, see Sort data.
If FALSE, VLOOKUP will only find an exact match. In this case, the
values in the first column of table_array do not need to be sorted. If
there are two or more values in the first column of table_array that
match the lookup_value, the first value found is used. If an exact
match is not found, the error value #N/A is returned.
Change the "TRUE" in your formula to "FALSE" and it should work.
= B37 * VLOOKUP(B36,A2:B5,2,FALSE)
Related
I'm trying to understand some legacy Excel file (it works, but I would really like to understand how/why it's working).
There is a sheet for data input (input sheet)and some code that is called to process data in the input sheet. I found out that number of rows in the input sheet is determined using a Lookup formula like this:
=LOOKUP(2;1/('Input sheet'!E1:E52863<>"");ROW(A:A))
"E" column contains names for import items and column is NOT sorted
"A" column does not contain anything special - I can replace it with B, C or whatever column and it does not affect the formula's outcome
According to what I have found about Lookup behaviour: •If the LOOKUP function can not find an exact match, it chooses the largest value in the lookup_range that is less than or equal to the value.
What does this ^-1 operation to the specified range? If E(x) is not empty -> it should turn into 1, but if it is empty - then it would be 1/0 -> that should produce #DIV/0! error...
1/('Input sheet'!E1:E52863<>"")
The outcome is the same, if I replace 2 with any positive number (ok, tried only some, but it looks like this is the case). If I change lookup value to 0, then I get #N/A error -> •If the value is smaller than all of the values in the lookup_range, then the LOOKUP function will return #N/A
I am stuck... can anyone shed some light?
LOOKUP has the rare ability to ignore errors. Conducting the 1/n operation will produce an error every time n is zero. False is the same as zero. So, for your formula, every empty cell produces an error in this calculation. All of those results are put in a vector array in the 2nd argument.
Searching for any positive value (the 1st argument) larger than 1 will result in LOOKUP finding the last non-error value in the above vector.
It also has the nice optional 3rd argument where you can specify the vector of results from which to return the lookup value. This is similar to the INDEX component of the the INDEX/MATCH combo.
In the case of your formula, the 3rd argument is an array that looks like this: {1;2;3;4;5;6;7;8;9;...n} where n is the last row number of the worksheet, which in modern versions of Excel is 1048576.
So LOOKUP returns the value from the vector in the 3rd argument that corresponds to the last non-error (non-blank cell) in the 2nd argument.
Note that this method of determining the last row will ignore cells that have formulas that result in a zero-length string. Such cells look blank but of course they are not. Depending on the situation, this may be precisely what you want. If, on the other hand you want to find the last row in column E that has a formula in it even if it results in a zero-length string, then this will do that:
=MATCH("";'Input sheet'!E:E;)
You might get some idea what the formula is doing (or any other formula) if you apply Evaluate Formula. Though since the principle is the same whether 3 rows or 52863 I'd suggest limiting the range, to speed things up if choosing Evaluate Formula. As usual with trying to explain formulae, it is best to start from the inside and work outwards. This:
'Input Sheet'!E1:E52863<>""
returns an array with a result for every entry in ColumnE from Row1 to Row52863. Since it is a comparison (<> does not equal) the result is Boolean - ie TRUE (not empty) or FALSE (is empty). So if only the first half of E1 to E52863 is populated, the result is {TRUE;TRUE;TRUE; ... and a LOT more TRUE; ... and FALSE ... and a LOT more ;FALSE and finally }.
Working outwards, the next step is to divide this array into 1. In arithmetic operations Boolean TRUE is treated as 1 and FALSE as 0, so the resultant array is {1;1;1; ... and a LOT more 1; ... and #DIV/0!... and a LOT more ;#DIV/0! and finally }.
This then becomes the lookup_vector within which LOOKUP seeks the lookup_value. The lookup_value you show is 2. But the array comprises either 1 or #DIV/0! - so 2 will never be found in it. As you have noticed, that 2 could just as well be 3, or 45 or 123 - anything as long as not a value present in the array.
That (not present) is necessary because LOOKUP stops searching when it finds a match. The fact that there is no match forces it to the end of the (valid) possibilities - ie the last 1. At this point, in my opinion, it would be logical to return "not found" but - I suspect merely a quirk, though very convenient - it returns that 1 - by its index number in the list, ie 52863 if all cells in E1:E52863 are populated.
Although the result_vector (Row(A:A)) is optional for LOOKUP it is required in this usage in effect to fix the start point for the index (effectively Row1, since an entire column). You might change that to say A3:A.. and the result would be the number of the highest populated row number in ColumnE plus 2 (3 -1).
Here is the screenshot of my excel workbook
I do not understand why the value in cell j7 is 44 ?
j7 formula is =LOOKUP(1,(TRIM($D$2:$D$9)=TRIM(H7))/(TRIM($E$2:$E$9)=TRIM(I7)),$F$2:$F$9)
The result of the two arrays division is the following
{TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE}/
{TRUE;FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE} =
{1;#DIV/0!;0;#DIV/0!;#DIV/0!;0;#DIV/0!;#DIV/0!}
Right ?
So I am looking for 1, basically the formula becomes
LOOKUP(1,{1;#DIV/0!;0;#DIV/0!;#DIV/0!;0;#DIV/0!;#DIV/0!},$F$2:$F$9)
Hence the result should be 10 but not 44 . . . . . ?
EDIT
When i correct my formula to =LOOKUP(1,1/(TRIM($D$2:$D$9)=TRIM(H7))/(TRIM($E$2:$E$9)=TRIM(I7)),$F$2:$F$9)
it works fine . Why ? Thank you everybody for giving the alternative solutions with match and index. I just can't understand why my first formula did not work. Any why when i add 1/ it MAGICALLY works ? ? ?
If the values are not in ascending order, and you are looking for a value within the range of values (as opposed to a value larger than anything in the range), LOOKUP may give unexpected results.
A different way to return the desired result is with a combination of INDEX and MATCH:
=INDEX($F$2:$F$9,MATCH(1,(TRIM($D$2:$D$9)=TRIM(H7))/(TRIM($E$2:$E$9)=TRIM(I7)),0))
entered as an array formula with ctrl-shift-enter
Note that with MATCH, looking for an exact match, the range does not need to be sorted.
Another formula that will return the correct results, and can be normally entered (assuming no duplicate entries in the first table):
=SUMPRODUCT((TRIM(H7)=TRIM($D$2:$D$9))*(TRIM(I7)=TRIM($E$2:$E$9))*$F$2:$F$9)
The explanation is:
with the first formula, the first array in the Lookup function contains zeros after the 1 value, in the third and sixth value of the array:
Lookup expects data to be sorted ascending and will return the first item less than or equal to the search value, starting from the last value in the array. In this case that is the zero value in the sixth position of the array.
The edited formula results in an array that contains only one number "1". All other values are Div errors. So the position of that "1" value is what Lookup will use.
Further explanation:
In your first formula you divide two arrays that contain TRUE or FALSE and the result contains 1, 0 and Div error values.
{TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE}/
{TRUE;FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE} =
{1;#DIV/0!;0;#DIV/0!;#DIV/0!;0;#DIV/0!;#DIV/0!}
Including the 1/ in the formula will divide the first array of TRUE and FALSE values by 1, which returns an array that consists of either 1 or Div errors. Further dividing that array by the second array will only return 1 or Div errors, no zeros. The steps are
1/{TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE}/{TRUE;FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE} results in
{1;1;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!}/{TRUE;FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE} results in
{1;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!}
No zeros!
As mentioned, LOOKUP expects the values in the lookup_vector to be in ascending order. To gain the first match of columns H & I to columns D & E, I would suggest mathematically excluding the non-matching rows. What is left would be the matching rows. The following example supplies the first double match.
For J2
=INDEX($F$2:$F$9,MIN(INDEX(ROW($1:$8)+(($D$2:$D$9<>H2)+($E$2:$E$9<>I2))*1E+99,,)))
Fill down as necessary. This is a standard formula and can be easily modified to supply the 2nd, 3rd, etc matching values by swapping SMALL() in place of MIN(). Your results should be close to the following.
This question is an extension of this - click me:
So I have 7 ordered checkboxes, generating 128 possible combinations of being checked/unchecked. Each checkbox is linked to a cell showing its state - true =1, false =0.
I then have a cell that concatenates the states of all 7 check boxes into a 7 digit string, e.g. 1000011 or 0000000 or 1110011, etc - providing a lookup value for my lookup table (which designates each possible combination to a piece of text).
The problem I am having is that vlookup is not finding the strings beginning with a leading 1, e.g. 1000001, or 1110000, or 1001110, etc, but strangely is matching one of the strings beginning with a leading 1 - "10000000". In other words, when I select only the first check box of the 7, I get text. When I select the first check box in addition to any combination of the other 6, I get an #N/A. When I deselect the first check box, with any combination of the others, I get text. Odd, I know.
Could anyone help with this?
Thanks in advance.
You might check if format at origin is equal to all values at destination, I mean, if you have for example 1000001 in lookup field as NUMBER and at lookup table you have the same value as TEXT, VLOOKUP never going to find it, because to Excel is not the same thing a value as NUMBER and a value as TEXT.
I'm almost sure that in your lookup table you have some values as NUMBER; to solve it you have to select only the column of your lookup table when you have all the possible combinations, then go to Data -> Text To Columns, then click Next -> Next -> Choose 'Text' Option -> Finish
Let us know if that worked for you.
Short answer: Supply FALSE as 4th VLOOKUP() parameter.
If it is omitted, range search is supposed to be TRUE and in such a case order of items in VLOOKUP() list matters, because they are understood as thresholds, not as singular values.
From VLOOKUP() help:
Lookup_value The value to search in the first column of the table array. Lookup_value can be a value or a reference. If
lookup_value is smaller than the smallest value in the first
column of table_array, VLOOKUP returns the #N/A error value.
And now read carefully:
Range_lookup A logical value that specifies whether you want
VLOOKUP to find an exact match or an approximate match:
If TRUE or
omitted, an exact or approximate match is returned. If an exact match
is not found, the next largest value that is less than lookup_value is
returned.
The values in the first column of table_array must be placed in
ascending sort order; otherwise, VLOOKUP may not give the correct
value. You can put the values in ascending order by choosing the Sort
command from the Data menu and selecting Ascending. For more
information, see Default sort orders.
If FALSE, VLOOKUP will only find
an exact match. In this case, the values in the first column of
table_array do not need to be sorted. If there are two or more values
in the first column of table_array that match the lookup_value, the
first value found is used. If an exact match is not found, the error
value #N/A is returned.
What I'm trying to do is use VLOOKUP to search through for an Alphanumeric serial number in a range of data in another sheet. However, it does not seem to be recognizing that there is a match when I know for a fact that there is and that they are formatted exactly the same.
The values I'm working with look like this: FTX1724R3W2
I've ran a =A1=B2 function and it returns TRUE.
I've copied and pasted one to the other to make sure that the formatting is the same, yet it still returns a #N/A.
Using MATCH returns a FALSE as well.
I'm not sure what's going on, do I need to specially format the Alphanumeric codes so that they are "searchable"?
Here is the VLOOKUP that I was using...
=VLOOKUP(L2498, Inventory_List!$A$1:$D$2176, 1, FALSE)
My final goal is that it finds it in the other sheet and returns the value in the first indexed column, which is the name of the inventory object.
VLOOKUP() searches the first column of the indicated range. For the function to be effective, have the serial number column be the leftmost column of your search range.
From Microsoft:
VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
Lookup_value The value to search in the first column of the table
array. Lookup_value can be a value or a reference. If lookup_value is
smaller than the smallest value in the first column of table_array,
VLOOKUP returns the #N/A error value.
Table_array Two or more columns of data. Use a reference to a range
or a range name. The values in the first column of table_array are the
values searched by lookup_value. These values can be text, numbers, or
logical values. Uppercase and lowercase text are equivalent.
Col_index_num The column number in table_array from which the
matching value must be returned. A col_index_num of 1 returns the
value in the first column in table_array; a col_index_num of 2 returns
the value in the second column in table_array, and so on.
I am using =IF(VLOOKUP(A2;$B$2:$B$11;B2;FALSE); TRUE; FALSE) to lookup a value in the column A.
As you can see my formula does not seem valid. Any suggestions why this is the case?
I appreciate your answer!
UPDATE
I am currently getting with =ISNUMBER(VLOOKUP(A2;$B$2:$B$11;1;FALSE)) only FALSE values. However I want to see True if there is a match:
Update
Using =Not(ISNA(VLOOKUP(A2;$B$2:$B$11;1;FALSE))) and =ISNUMBER(MATCH(A2, $B$2:$B$11, 0)) gives me the same result:
VLOOKUP takes the following arguments:
=VLOOKUP(lookup_value; table_array; col_index_num; [range_lookup])
lookup_value is what will be looked for in the first column of table_array.
table_array is the table in which the lookup_value and the value to be returned are.
col_index_num is the number indicating the nth column within table_array from which the value is to be returned from.
[range_lookup] (defaults to true) indicates the type of lookup, true being approximate and false being exact.
As such, if you want to find if A2 is in table $B$2:$B$11, you need to use a col_index_num of 1.
A simpler formula however would be with MATCH:
=ISNUMBER(MATCH(A2; $B$2:$B$11; 0))
MATCH returns the relative row number in which the value A2 is found. If there is a match, you get a number and hence ISNUMBER returns TRUE.
If you want to check if a value from column B exists in column A, then you have it reversed in the formula you used. Turning it around gives:
=ISNUMBER(MATCH(B2; $A$2:$A$11; 0))
You could also use COUNTIF, i.e. this formula in C2 copied down
=COUNTIF(A$2:A$11,B2)>0