I am trying to do a VLOOKUP but its just not going to cut the mustard. There is no way I can alphabetize the first column in my list.
What I am wondering is there any alternatives or combinations of functions that I could use along VLOOKUP in the case that the list can not be alphabetized?
From the link in your comment on your OP:
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.
It isn't terribly obvious the way that document is formatted, but the qualification that the lookup range must be sorted ascending only applies for when the 4th argument in VLOOKUP is TRUE, or a non-zero positive number, or omitted. (If the 4th argument is a non-zero negative number, the first column must be sorted descending.) In these cases, you are allowing the formula to return a non-exact match.
If you are looking for an exact match only, then you must specify FALSE (or zero) for the 4th argument, and the first column needn't be sorted at all.
If you are looking for an non-exact match on an unsorted range, then something like this should work in Google Sheets (assuming you are looking for a match of C1 in column A, and returning the corresponding entry in column B):
=INDEX(SORT(FILTER(A:B;LEN(A:A));1;1);MATCH(C1;SORT(FILTER(A:A;LEN(A:A));1;1));2)
DGET - there are a bunch of database style functions in google spreadsheets, I suspect DGET is the one you want.
Plain Text: With vlookup 1 and "1" are not the same. If you format the column as plain text it can do the lookup. This works even if your cell has a formula that produces a number.
Related
What I'm trying to do is find the name of the person who is ranked number 1 in the table shown below. I have tried =LOOKUP and =VLOOKUP but I get an error saying that a result can't be found, even though it's obviously there. I assume that I'm either using the wrong function or just not using it right.
I tried =VLOOKUP(1;D2:H19;1) and =LOOKUP(1;D2:H19;1) but neither seems to work.
Answer
The following formula should produce the behaviour you desire:
=INDEX(D2:D,MATCH(1,H2:H,0))
Explanation
=VLOOKUP can only be used to find values to the right of a search key. To find values to the left of a search key, use a combination of =INDEX and =MATCH.
The =MATCH function searches a specified range for a specified value and returns the relative position of the value in that range. In this case, the value to search for is 1, the range to search through is H2:H, and the 0 at the end specifies that the range is not sorted in any way.
The =INDEX function returns the contents of a cell within a range having a specified row and column offset. In this case, the range is D2:D, and the row is whichever row is returned by =MATCH. =INDEX could take a third argument if it was desired to specify a row offset as well, but that is not necessary here.
Functions used:
=INDEX
=MATCH
You sort your ascending order based on rank then return your desired data using INDEX() function. Try-
=INDEX(SORT(D2:H500,5,1),1,1)
=vlookup(1,{H2:H19, D2:D19},2)
Since vlookup only searches the 1st column of the input range, to use it, you need to flip the columns by composing a local array: {H2:H19, D2:D19}.
{} means concatenation. , in it means horizontal concatenation. With that, the rank column is now the 1st column in the input of vlookup and now vlookup works.
With our local array, the 2nd column are the names and therefore index should be 2.
Also note the use of comma to separate function inputs.
your VLOOKUP formula should look like:
=VLOOKUP(1, {H2:H19, D2:D19}, 2, 0)
also try just:
=FILTER(D:D; H:H=1)
or:
=SORTN(D:D; 1; 1; H:H; 1)
You can use query (usefull in case of ex aequo)
=query(D2:H,"select D where H=1",0)
I need to find the last numerical value in a column. I was using this formula to get the last value in column G, but I made some changes and it no longer works: =INDEX(G:G, COUNTA(G:G), 1). My column now looks like this:
645
2345
4674.2345
123.1
"-"
"-"
"-"
...and the formula returns "-". I want it to return 123.1. How can I do this?
There are many ways to go about this. Here is one of them:
=QUERY(FILTER({G:G,ROW(G:G)},ISNUMBER(G:G)),"Select Col1 ORDER BY Col2 Desc LIMIT 1")
FILTER creates a virtual array of only numeric values in G in the first column and the row of those numeric values in the second column.
QUERY returns flips the order by row number and returns only the new top value from the first column (which winds up being your last numeric value in the original range).
However, if your numeric values start at G1, and if there are only numeric values up to where you start adding hyphens in cells, you could just alter your original formula like this:
=INDEX(G:G,COUNT(G:G))
This would work because COUNT only counts numeric values while COUNTA counts all non-null values (including errors BTW).
Not to take anything away from the accepted answer, but I've been working on this a bit lately in relation to this for the never-ending last row discussion and thought I'd share some potential similar solutions. These ideas are inspired by a pattern of google sheet array questions that seem to be coming up more often. I am also intentionally using different ways to do the same thing just to give people some ideas (i.e. left and Regex).
Last Row that is...
Number: =max(filter(row(G:G),isnumber(G:G)))
Text: =max(filter(row(G:G),isText(G:G)))
An error: =max(filter(row(G:G),iserror(G:G)))
Under 0 : =max(filter(row(G:G),G:G<0))
Also exists in column D: =max(filter(row(G:G),ISNUMBER(match(G:G,D:D,0))))
Not Blank: =max(filter(row(A:A),NOT(ISBLANK(A:A))))
Starts with ab: =max(filter(row(G:G),left(G:G,2)="ab"))
Contains the character !: =max(filter(row(G:G),isnumber(Find("!",G:G))))
Starts with a number: =max(filter(row(G:G),REGEXMATCH(G:G,"^\d")))
Only contains letters: =max(filter(row(G:G),REGEXMATCH(G:G,"^[a-zA-Z]+$")
Last four digits are upper case: =Max(filter(row(G:G),REGEXMATCH(G:G,"[A-Z]{4}$")))
To get the actual value (which I realize was the actual question), just wrap an index function around the Max function. So for this question, a solution could be :
=Index(G:G,max(filter(row(G:G),isnumber(G:G))))
Ok, this is the updated linkI have multiple criteria to look through in my arrayformula(index(match())). The first two are simple as they reference the row the formula is calculating on. The last conditional I have is to find the highest occurrence in a given range, but ONLY if the other conditions are met...something like a filtered maxifs..any ideas?
Here is my code in column P =iferror(ArrayFormula(index($F:$F,match(1,("Fee Taken"=$C:$C)*(H12=$H:$H)(maxifs($M:$M,$H:$H,H2,$C:$C,"Fee Taken"),0))),""))
The result that I would like is to return from column F if the name matches that rows name, the transaction type is "Fee Taken" from column C, and THEN if those conditions are true I want it to find the max value from column M based on those two criterias and return the column F value for that max value row..
Ive attached some pictues to show my data.
The last part of the Match function where I have the Maxifs equaling to eachother is where I am confused; my thoughts were to see if the maxifs for the item in Column "M" can be used as a criteria..but I do not think so....I only want the highest occurence F:F if both conditions are met and it is the highest value for both those criteria in column M..
Please let me know if you need anymore info..Thanks![
Working formula will be:
=ArrayFormula(index($F:$F,match(1,--(M:M=(maxifs($M:$M,$H:$H,H2,$C:$C,"Fee Taken"))),0)))
I am using Google Sheets and the VLOOKUP formula within it. Why does the following formula return a 0?
Columns C2:Q150 are generated from a formula and number's pulled from other sheets. Columns U4:U18 are generated by using the LARGE function (to find max in a sorted manner)
According to the documentation you posted, Google Sheet's VLOOKUP function works in the same way as Excel's.
So you are looking in the range $C$2:$C$150 (the first column of your table, which you specified as $C$2:$Q$150) to find the last value in that column that is less than or equal to your 36, i.e. the value in cell U4, and then returning the value in the first column of your $C$2:$Q$150 range on the found cell's row.
If the last cell in column C contains a zero, the answer will be 0.
Re the fourth parameter (which you are setting to TRUE), the documentation says in its Notes:
If is_sorted is set to TRUE or omitted, and the first column of the range is not in sorted order, an incorrect value might be returned. If VLOOKUP doesn’t appear to be giving correct results, check that the last argument is set to FALSE. If the data is sorted and you need to optimize for performance, set it to TRUE. In most cases it should be set to FALSE.
For excel try this in V4,
=INDEX(A:A, AGGREGATE(15, 6, ROW($2:$20)/(C$2:Q$20=U4), COUNTIF(U$4:U4, U4)))
Fill down as appropriate.
In google-sheets this translates to,
=index(A:A, small(if(C$2:Q$20=U4, row($2:$20)), countif(U$4:U4, U4)))
The following spreadsheet demonstrates a very odd behaviour of Google Spreadsheets Lookup functions. I've used these functions many times without any problem. Can anyone confirm it happens on their side as well?
Example doc: https://docs.google.com/spreadsheets/d/16lRQ72K28CtObY_ChzpNQUVTl_EgbjEyRcpP5QOZKzE/edit?usp=sharing
By Default VLOOKUP does approximate matches. #Pnuts explained that the desired result is not being returned in every case because the the search is binary.
Excels optional parameter for VLOOKUP is called range_lookup and quote:
range_lookup Optional. A logical value that specifies whether you
want VLOOKUP to find an exact match or an approximate match:
If range_lookup is either TRUE or is 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.
IMPORTANT If range_lookup is either TRUE or is omitted, the values
in the first column of table_array must be placed in ascending sort
order; otherwise, VLOOKUP might not return the correct value.
For more information, see Sort data in a range or table.
If range_lookup is FALSE, the values in the first column of
table_array do not need to be sorted.
If the range_lookup argument is FALSE, VLOOKUP will find only an exact
match. 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.
Google's optional parameter for VLOOKUP is called is_sorted and quote:
is_sorted - [OPTIONAL - TRUE by default] - Indicates whether the
column to be searched (the first column of the specified range) is
sorted.
If is_sorted is TRUE or omitted, the nearest match (less than or equal
to the search key) is returned. If all values in the search column are
greater than the search key, #N/A is returned.
If is_sorted is set to TRUE or omitted, and the first column of the
range is not in sorted order, an incorrect value might be returned.
If is_sorted is FALSE, only an exact match is returned. If there are
multiple matching values, the content of the cell corresponding to the
first value found is returned, and #N/A is returned if no such value
is found.
If you need exact matching with VLOOKUP just add FALSE in the optional parameter to force the lookup of exact matching. If you are using the MATCH then add a 0.
So the formulas for your spreadsheet should look like:
=VLOOKUP(A2,A1:E13,5,FALSE)
=VLOOKUP("n1-standard-2",A1:E13,5,FALSE)
=MATCH(A2,A1:A13,0)
=MATCH("n1-standard-2",A1:A13,0)
=HLOOKUP(A1,A1:E13,5,FALSE)
=HLOOKUP("n1-standard-1",A1:E13,5,FALSE)