I am trying to figure out if it is possible to use LOOKUP function that is based on a dyanmic value. For example:
=LOOKUP("A", C$2:C$1000, B$2:B$1000)
The above will look for Letter A in C Column and then write the value from the corresponding B Column row. What I wish to do is now read the Letter A from the D column, like so:
=LOOKUP(D2, Sheet2!C$2:C$1000, Sheet2!B$2:B$1000)
However, the above gives me an error. Is there a way to accomplish the above?
The above keeps returning me with an error saying value not found, I'm not sure what I am doing wrong.
EDIT
Ok so I have been playing more with this and I started having some very strange results. Lets take the following table: https://docs.google.com/spreadsheets/d/1ki3pmCOQoI1DLcbjEO-uwgwZGFfnHhM-fodspw8v1Qs/#gid=1001637055
Then my second sheet is this:
https://docs.google.com/spreadsheets/d/1ki3pmCOQoI1DLcbjEO-uwgwZGFfnHhM-fodspw8v1Qs/edit#gid=1993578337
If you look at the second sheet, bob shows up multiple times and I don't understand why.
Reason for #N/A's
lookup produces #N/A if it is looking up an empty range as is the case here. `'Draft Options'!A:A is empty so lookup cannot find a value to look up against.
Reason for multiple appearances
The documentation states that:
The LOOKUP function will only work properly if data in search_range or
search_result_array is sorted. Use VLOOKUP, HLOOKUP, or other related
functions if data is not sorted.
If search_key is not found, the item used in the lookup will be the
value that’s immediately smaller in the range provided. For example,
if the data set contains the numbers 1, 3, 5 and search_key is 2, then
1 will be used for the lookup.
Now, you are looking up Text but the same thing applies, it needs to be ordered alphabetically.
This is because lookup is doing something called binary search
Since your data is unordered and (assuming you have column A filled with keys the following can happen which leads to weird results:
Lookup looks at the middle entry and checks if the value comes before or
after the lookup value in an alphabetically sorted list.
If it comes
before it checks the the entry int he middle between the beginning
of the list and the middle.
If your entry happens to be in the latter half lookup never finds this entry
or
This value might not exists so it picks the first value it can find that would come before that (assuming the data is sorted) or something (seemingly random) where lookup finds value n to be alphabetically after the lookup value and n+1 alphabetically before and returns value n+1.
You should only use lookup if you know the lookup values will be there and that they will be sorted. Otherwise you might want to take a look at VLookup or Index Match
Solution
If Column A in Sheet Draft options Actually contains those letters you are looking up you can use a simple VLookup:
=VLOOKUP(F2, `Draft Options`!$A$2:$B$1000, 2, FALSE)
Here FALSE specifies that VLookup shall not use a binary search algorithm and instead go through the list linearly (i.e. one by one) which is slower but will retrieve the first matching value or throw an error if it is not there instead of returning something odd.
Related
i'm using the quartile.inc() function in a pivot table. The column I'm using is SUM of profit. It doesn't have any 0 values in there (they have been filtered out) yet it keeps returning a 0 value.. Here's a screenshot of the function in question
I've made sure the data type is numeric across all tables, i've filtered out the $0.00 values. I know for a fact the correct value it should return in 15.08. The customer_ids have only blanks and one other id filtered out. Everything else works great except this.
You can try this:
=quartile.inc(filter($D$2:$D$3494,map($D$2:$D$3494,lambda(x,subtotal(103,x)))),0)
As pointed out Google Sheets lacks the AGGREGATE function Excel has which is able to perform aggregations like quartiles ignoring filtered rows; only the more basic SUBTOTAL function is available which retains the ability to ignore filtered rows but lacks more complex aggregations.
However, by using SUBTOTAL(103 (COUNTA ignoring filtered rows) within a MAP over a filtered vertical range you can obtain the filter status of each row as an array; this can be used as the condition argument to the FILTER function to obtain the filtered source cells as an array, which can then just be passed into QUARTILE.INC.
I'm creating a crypto tracking spreadsheet and I'm getting some strange results using the LOOKUP function.
I have two named ranges:
The symbol range is called USDCoinSymbols
and the coin name range is called USDCoinNames
Here are some function results when I try using the LOOKUP function:
Apologies for the mixed casing on the search term. I was experimenting, but
it seems the LOOKUP function isn't case sensitive (for example, BNB returned the correct coin name).
I also tried the inverse, looking up a coin symbol with a coin name (2nd result) and that works fine.
I spent a good couple hours trying to figure this out.
Am I missing something or is this a bug?
Edit: Here is a link to sample spreadsheet and I'm using the CoinGecko API to get this data.
I'm trying to pull the coin name using the symbol to fill up a table I'm creating.
This is not a bug. It's just how LOOKUP works.
LOOKUP requires that all search-column information be in strict least-to-greatest order, so it wouldn't work with your data.
I've added a new sheet ("Erik Help") which is a duplicate of your first sheet. In my sheet, I deleted your LOOKUP formulas from B20:B27 and replaced them with one array formula. This formula uses VLOOKUP with FALSE as the final parameter, meaning that your data is NOT ordered in strict least-to-greatest order and that exact matches should be searched anywhere instead. This one formula fills all results for B20:B:
=ArrayFormula(IF(A20:A="",,IFERROR(VLOOKUP(A20:A,B2:C14,2,FALSE))))
If you are going to be applying this to a larger list elsewhere and want to use your named ranges, just replace B2:C14 with {USDCoinSymbols, USDCoinNames}.
References:
LOOKUP
VLOOKUP
You will need to use the VLOOKUP function instead
=INDEX(IFERROR(VLOOKUP(A20:A25, {USDCoinSymbols, USDCoinNames},2,0)))
This single formula is all you need.
Since your lists are NOT sorted you should use 0 in the function
(please -as always- adjust formula according to your ranges and locale)
In a sheet made of names and scores, I am trying to build a sheet to display the name of the people with the best scores.
To do so:
I sort the scores
I get the index of the biggest value
I offset the names list with the given index
When I want to get the second biggest value, I only have to get the index of the second biggest value on step 2.
There is a problem if two values are tied for the biggest, as MATCH() will always give me the index of the first value found.
I thought of determining the index of the biggest value, then excluding this index from the range used to determine the second biggest value, but I could not achieve it as the range lengths may be different.
I also thought of using a function or script that returns the Nth index that meets a criteria from a range, but I did not find anything to do so.
Image
Here is an example spreadsheet
https://docs.google.com/spreadsheets/d/1RrUpAjbMBze9L5OqxdyEWBnYXq98LtohdgROF8s68FI/edit?usp=sharing
One way is to add a column number and sort on that as well as on the score, then take the second element in the list:
=ArrayFormula(index(sort(transpose({B1:F3;column(B1:F3)}),3,false,4,true),2,1))
Note that the headers (players' names) are sorted along with their scores.
EDIT
Actually Sort in GS is a stable sort (in other words, according to the documentation 'range is sorted only by the specified columns, other columns are returned in the order they originally appear') so this is sufficient:
=ArrayFormula(index(sort(transpose(B1:F3),3,false),2,1))
I want to create a formula, that gets me the specific value(s) from row in another table. The formula I've created
=LOOKUP(E5;Ingredients!$A$6:$B$49;Ingredients!$F$6:$F$49)
gives me false results. But when I sort the values by alphabet the results are correct.
Is there some way to create a formula that is not dependent on alphabetical sort of source table?
From https://support.google.com/docs/answer/3256570?hl=en-GB
"Notes:
The LOOKUP function will only work properly if data in search_range or search_result_array is sorted. Use VLOOKUP, HLOOKUP or other related functions if data is not sorted."
Personally, I've never really used the lookup functions because of issues like this, so I'm a bit rusty on the specifics of how they all work. My go-to is the INDEX MATCH solution, which might be something like
=index(Ingredients!$F$6:$F49, match(E5, Ingredients!$A$6:A$49))
What I'm also not sure about is how Lookup is supposed to work when you're giving it more than one column as the input, though; you're giving it A and B - I thought that syntax was for an array where the output comes from the last column, and I don't know what happens if you then specify the output column as well, as you've done.
I would like a script to delete columns in a Google Spreadsheet if the contents match a list of approximately 30 possible text strings. e.g. Custom Variable 1, Custom Variable 3, Custom Variable 9, etc.
I'm new to Google Scripts. I've searched this forum but haven't found a starting point that handles my specific situation -- deleting columns based on a list of string values rather than a single value or value input from a dialogue box.
Any help would be greatly appreciated.
Scott C
If I'm understanding what you're asking, you wish to read through a column and compare a list of values to the value in each row of that column. If that column contains any one of those 30 values, delete that column.
One way you could do it:
Hard code an array that contains all of those values you have in mind. Loop over the column you desire, storing each value into an array (So you would have two arrays total when you're done. One with the hard coded values, the other with the column values). Then, take those values from Array 2, and see if they match any of the words in Array 1. If one of those values matches your list, delete that column.