Excel Lookup/Search and Match - excel

I am trying to get to the bottom of an issue I have been struggling with for days, in my example I have to match what is in column G to what is in column A whether it be a complete match or a partial match, then check that the Qty matches and pull across the Sal value. My example works with an exception. If an ID appears multiple times in my Lookup table but has different Qty, it only validates the last one in my reference table. I have put this in to my attached example.
=IFERROR(IF(H2=LOOKUP(2^15,SEARCH($A$1:$A$12,G2),$D$1:$D$12),LOOKUP(2^15,SEARCH($A$1:$A$12,G2),$C$1:$C$12),"Qty Issue"),"UnKnown ID")
I have this in an example file but unfortunately no way to upload it.
Download File

Closest formula put to J2, as your expected K7 (60) and K11 (0) values has no logic
=SUMIFS($C$1:$C$12,$A$1:$A$12,LOOKUP(2^15,SEARCH($A$1:$A$12,G2),$A$1:$A$12),$D$1:$D$12,H2)
Syntax
LOOKUP(lookup_value, lookup_vector, [result_vector])
If the LOOKUP function can't find the lookup_value, the function
matches the largest value in lookup_vector that is less than or equal
to lookup_value.
If lookup_value is smaller than the smallest value in lookup_vector,
LOOKUP returns the #N/A error value.

Related

Excel Vlookup table array is throwing NA error [duplicate]

"The range where the lookup value is located. Remember that the lookup value should always be in the first column in the range for VLOOKUP to work correctly. For example, if your lookup value is in cell C2 then your range should start with C."
But sometimes I want to be able to do dual-direction lookups. Ie, lookup using a key in column A to get the value in column B AND at the same time, in other formulas, lookup the value in B to get the value in A.
The only way I know is to add a column C which mirrors A, then use AB for the first lookup, and BC for the second lookup. But there has to be some cleaner solution. Is there some way to force VLOOKUP to use a different column other than the first one to find the key value, or is there a different function that would allow the equivalent?
As a side note, I am asking about Excel, but I actually use LibreOffice. Presumably the functions should be identical, but an answer that also works in LibreOffice would be preferable.
INDEX/MATCH will do it any direction of search.
So for your example of B --> A:
=INDEX(A:A,MATCH(yourCriteria,B:B,0))
The MATCH returns the row number of the match. The third Criterion of 0 is optional. The 0 is the same as FALSE for the forth criterion of VLOOKUP, in that it looks for an exact match.
The default is 1 with the data sorted it will return the match that is less than or equal to the criteria Like VLOOKUP's TRUE.
From that the INDEX finds and returns the correct value.
With the introduction of the Dynamic Array formula XLOOKUP we can use:
=XLOOKUP(yourCriteria,B:B,A:A,"",0)

How can I get the location of a cell in Excel based on its value if it's not the first one in the column?

I know how to use index and match formulas to get the value or location of a matching cell. But what I don't know how to do is get that information when the cell I'm looking for isn't going to be the first match.
Take the image below for example. I want to get the location of the cell that says "Successful Deliveries". In this example there's a cell that matches that in rows 11 and 30. These locations can vary in the future so I need a formula that's smart enough to handle that.
How would I get the location of the second instance of "Successful Deliveries"? I figured I could use the "Combination 2 Stats" value from row 24 as a starting point.
I tried using this formula:
=MATCH("Successful Deliveries:",A24:A1000,0)
But it returns a row number of 7 which is just relative to the A24 cell I started my match at.
My end goal here is to get the value from the cell directly to the right of the second match of "Successful Deliveries".
In your formula, with no further intelligence, you can simply add 23 to adjust 7 to the result:
=MATCH("Successful Deliveries:",A24:A1000,0) + 23
You know that 23 is the number to add because you started your search on row 24.
The full answer is here:
https://exceljet.net/formula/get-nth-match-with-index-match
You use this formula:
=INDEX(B1:B100,SMALL(if(A1:A100 = "Successful Deliveries:",ROW(A1:A100) - ROW(INDEX(A1:A100,1,1))+1),2))
...where 2 is the instance you want.
Make sure to finish typing the formula by hitting ctrl-shift-enter. (You know you did this right because the formula gets curly brackets {})
HOW IT WORKS
Normally, we use INDEX / MATCH to find a value. The Index function gives you the nth value in a range, and the Match function determines which "n" is a match for our criteria.
Here we use INDEX the same way, but we need more intelligence to find that "n", since it's the second one that matches the criteria. That's where SMALL comes in. The Small function "gets the nth smallest value in an array". So we give Small the number of the desired instance (2 in this case) and we give it an array of blanks and the rows numbers of the rows we like.
We obtained the array of blanks and row numbers using the If function, asking it to check for our criterion (="Successful...") and making it return the row number where the criterion passes (=Row(A1:A100)). By using the If function as an array function (by giving it arrays and using ctrl-shift-enter) it can deliver a whole list of values.
Our final value is just one number because the Small function used the array from the IF to return just one thing: the second-smallest row we gave to it.

Excel VLOOKUP where the key is not in the first column

"The range where the lookup value is located. Remember that the lookup value should always be in the first column in the range for VLOOKUP to work correctly. For example, if your lookup value is in cell C2 then your range should start with C."
But sometimes I want to be able to do dual-direction lookups. Ie, lookup using a key in column A to get the value in column B AND at the same time, in other formulas, lookup the value in B to get the value in A.
The only way I know is to add a column C which mirrors A, then use AB for the first lookup, and BC for the second lookup. But there has to be some cleaner solution. Is there some way to force VLOOKUP to use a different column other than the first one to find the key value, or is there a different function that would allow the equivalent?
As a side note, I am asking about Excel, but I actually use LibreOffice. Presumably the functions should be identical, but an answer that also works in LibreOffice would be preferable.
INDEX/MATCH will do it any direction of search.
So for your example of B --> A:
=INDEX(A:A,MATCH(yourCriteria,B:B,0))
The MATCH returns the row number of the match. The third Criterion of 0 is optional. The 0 is the same as FALSE for the forth criterion of VLOOKUP, in that it looks for an exact match.
The default is 1 with the data sorted it will return the match that is less than or equal to the criteria Like VLOOKUP's TRUE.
From that the INDEX finds and returns the correct value.
With the introduction of the Dynamic Array formula XLOOKUP we can use:
=XLOOKUP(yourCriteria,B:B,A:A,"",0)

Excel index match equal or greater than value error

hello first of all this is my code which returns the error
=INDEX(Steel_table!A3:A151,LOOKUP(10^10,MATCH(H7,Steel_table!C3:C151,{1,0})+{1,0}))
i have based this code from this thread:
Use INDEX MATCH to find greater than/equal to value
This is the scenario
i have 2 sheets namely, stress analysis and steel table
the value that i would like to compare is located in the stress analysis sheet cell H7 and i would like to compare it to the steel table sheet from cell's values from C3 until C151.
please help me as it always returned an #N/A error
Stress Analysis Sheet
Steel Table sheet
Many thanks
The use of third argument to MATCH functions must be considered depending on whether the lookup range is sorted or not.
The only time the range sort need not be taken into account is when using 0 - exact match. But exact match is not what you need since you are looking up calculated results against a table of prefixed values which won't likely be exactly matched...
So in order to use third argument of 1, the looking range should be sorted in ASCENDING order. In your case teh second value of the lookup range is larger than your lookup value, and so is the first, so Excel shortcuts to N/A, assuming that no smaller value will be found further down.
The reverse logic is true for using -1.
You can simply use the difference of the lookup values and the range to obtain the smallest one. So we use the MIN function. But you only want positive differences , so you'll need to transform all negative numbers into a ridiculously large number(such as 10^10), so that they are not used as potential minimum values:
INDEX(Steel_table!$A$3:$A$151, MATCH(MIN(IF(Steel_table!C3:C151-H7>=0, Steel_table!C3:C151-H7, 10^10)), Steel_table!C3:C151-H7,0))
This will give you the smallest value in Steel_table!C3:C151) that is equal or greater then the value in cel H7:
=MIN(IF((Steel_table!C3:C151)>=H7,(Steel_table!C3:C151)))
It is an array formula, so confirm with [Control-Shift-Enter]. The output will be 1451.61. It will return 0 when there is no equal or greater value.

ms excel 2007, vlookup #n/a error

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.

Resources