VLOOKUP formula cannot read dataset generated by another formula - google-sheets

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)))

Related

How can I find the name of the person ranked 1?

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)

Google Sheets Fill Down with Formula

I have a very hard problem to solve, which must be completed with a formula (not a script).
Basically, the Raw input column needs to be dynamically filled down until it hits the next piece of text.
Here's an example file with includes the expected output.
https://docs.google.com/spreadsheets/d/1ibqCvY39NlhCRWsbBdxKITUUpVpp9wXdEz44T-pHDY0/
Is it even possible to achieve?
Thanks
This will work based on your ask, assuming that A2 is never blank, place this in the first row of data (not header):
=ArrayFormula(IF(A2:A<>"", A2:A, B1:B))
It checks to see if there is a value in column A, if there is, it fills that column, if not, it copies the cell above.
Delete everything in Column B (including the header) and place the following formula in B1:
=ArrayFormula({"Header";VLOOKUP(FILTER(ROW(A2:A),ROW(A2:A)<=MAX(FILTER(ROW(A2:A),A2:A<>""))),FILTER({ROW(A2:A),A2:A},A2:A<>""),2,TRUE)})
Here is a basic explanation of how this formula works:
A virtual array is created between the curly brackets { }; this virtual array contains a header and all results. You can change the header name to whatever you like.
VLOOKUP looks up every row number that is less than or equal to the highest row number that contains text in A2:A. Each of these qualifying rows is looked up in a second array that contains only the row numbers and Column-A data from non-blank rows, returning the data itself. Since rows are in perfect ascending order and the last parameter of VLOOKUP is set to TRUE, all blank rows in the first array will "fall backward" to find the most recent row that did have something in Column A.

HLOOKUP evaluates to an out of bounds range error in Google Sheets

I'm trying HLOOKUP with Importrange formula as I've to lookup data from other Google Sheets.
I'm entering the below formula.
=HLOOKUP(C1,IMPORTRANGE("1wWguGb6O0GyX7ACxzoFCN8N73zV0pUeoj51R_zFNPfE","Project wise Resources!$E$1:$AZ$20"),2,0)
I'm getting the error:
HLOOKUP evaluates to an out of bounds range.
I have entered the correct range but unable to understand what the issue is.
you can't do that on the spot
first paste this formula into some cell and allow access
=IMPORTRANGE("1wWguGb6O0GyX7ACxzoFCN8N73zV0pUeoj51R_zFNPfE",
"'Project wise Resources'!E1:AZ20")
then use your formula:
=HLOOKUP(C1, IMPORTRANGE("1wWguGb6O0GyX7ACxzoFCN8N73zV0pUeoj51R_zFNPfE",
"'Project wise Resources'!E1:AZ20"), 2, 0)
and also make sure that sheet Project wise Resources has a column AZ
Try changing last HLOOKUP option to TRUE/FALSE instead of 0
HLOOKUP: https://support.google.com/docs/answer/3093375?hl=en
Horizontal lookup. Searches across the first row of a range for a key
and returns the value of a specified cell in the column found.
VLOOKUP: https://support.google.com/docs/answer/3093318?hl=en&ref_topic=3105472
Vertical lookup. Searches down the first column of a range for a key
and returns the value of a specified cell in the row found.
IMPORTRANGE:
https://support.google.com/docs/answer/3093340?hl=en
you may need VLOOKUP depending on way your lookup is organised - by rows or columns..
If you are lookup up second row or second column only, then there is no need to have a range that extends beyond 2 rows or 2 columns...

Google spreadsheets: conditional formatting with custom formula based on values from different sheet

I have a google spreadsheet with two sheets. On the first sheet, the items are listed in column A, and their types are in column B.
On the second sheet, I reference to the first sheet's column A with the formula: =UNIQUE(Sheet1!A:A).
Then I want to color the items in the 2nd sheet based on the item type (1st sheet's column B*). I try to add conditional formatting using the formula =Sheet1!$B:$B="Type1", but when I try to save rules, it says the formula is invalid.
What would be the correct formula for this case?
You cannot reference cells directly in the conditional format formula. Also, I do not think that formula would work.
First, you need the VLOOKUP function to get the object's type.
Here's an example of using this function. The difference would be that the corresponding data in the first parameter would be preceded by the sheet name in your case.
See this image:
As you can see, VLOOKUP searchs for the item from D in the matrix A2:B4, and then returns the corresponding value (the value in the same row) in the second column of the matrix, which is column B.
So if you to apply this formula to conditional formatting, you would have:
=VLOOKUP($D$2:$D;$A$2:$B$4;2)="Dragon"
The first parameter of VLOOKUP has to be a range, and I started it from D2 so it would not match the header. In your case, it would become:
=VLOOKUP($D$2:$D;Sheet1!$A$2:$B$4;2)="Dragon"
But as you cannot use references directly, you need to use the INDIRECT function. It receives a cell range as a string and returns a reference to that range. It's the same as using references directly, but in this case you add an extra step (go figure). So the formula finally becomes:
=VLOOKUP($D:$D;INDIRECT("$A$2:$B$4");2)="Dragon"
You can choose any range to apply the format if you are using the new version of Spreadsheets. You could, for example, color the entire row or just a single cell.

VLOOKUP alternatives

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.

Resources