Google Sheets vlookup for multiple results - google-sheets

Trying to find a vlookup formula that will return all of the matches not just the first on in the list. I have used the following formula
=VLOOKUP(A2,C:D,2,0)
I'm sure there's a way to do this I just haven't been able to figure this out on my own.
Results that I need vs what I get

Vlookup will always return the first occurrence value, therefore you will not be able to extract 2nd or 3rd value. One of the simple method to obtain nth return is to use index function together with filter as following:
=INDEX(FILTER(A:B,A:A=D2),COUNTIF($D$2:D2,D2),2)
The countif will return 1st, 2nd or 3rd row after filtering the main table:

Related

Google Sheets LOOKUP Function returning the wrong values?

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)

Formula for looking up and filtering data from a sheet

I want to do a complex formula using google sheets:
I have a list of place that will be visited by different people.
Some places are not to be visited, marked with /
Some places need to be assigned, marked with ?
Wanted outcome:
A list of cells that changes every day automatic.
An overview of who is going where that day and what needs to be assigned.
So I need a formula that can select a row based on today() and then filter out Persons in that row. Then for each person, another formula that looks up the first row in the table and puts duplicates together.
Example:
Wanted outcome:
Link to excel file, but it needs to work in google sheets too: xlsx
My solution is not the most elegant but it does the job.
First I build a column with date and unique persons or ? in this column:
=unique(sort(transpose(index(A1:H10,match(today(),A1:A10,0)))))
Then I find Places corresponding to these persons (I use filter function for it and then I use textjoin to keep them in single cell).
The formula is copied down as filter function does not accept a range and arrayformula as a filtering criterium.
My solution is available here:
https://docs.google.com/spreadsheets/d/1GTy_UaFP8LbA8OLnEhT_R_twpDCIWCuvQfBAigqtbR0/copy

vlookup or index match give no result

i have a problem with a vlookup and also index&match formula.
First i transpose split and substitute a result from an api call which is in JSON, then i get a list i can use vlookup with, but when trying the result is allways #N/A.
=transpose(split(H7;",")) and =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(E18;"[";"");"]";"");" ";"") are the formulas to get a short list of numbers i would like to use a search for a result and this is existing, because when i replace the formula with the result for what i am looking for with a "normal number", then i get the response from a vlookup or index&match!
Would be cool if someone has an idea for this so i can bring it to work.
It turns out as necessary to delete empty rows from other related sheets without content in it to make it happen to work for this kind of sorting data with index and match.

How to use ARRAYFORMULA + FILTER within Google Spreadsheet?

I have a Google spreadsheet with basically a dictionary of key/value pairs. Keys are unique. In a second sheet I need to add one or more rows for every key in the dictionary with some data. In this very sheet I'd need to also report the proper value for each key.
To do so I have tried to combine the ARRAYFORMULA function with a number of other functions on the very first row of the second sheet to avoid (if possible) the need to copy the same formula on all rows of the value column.
So far, neither QUERY nor FILTER worked.
QUERY requires all data, there included the arguments to the WHERE predicate, to reside on a single sheet. In my case, the filtering key would be on the second sheet while the dictionary is on the first one. So this cannot be used at all.
FILTER seems to have a weird (to me) behavior when both used in conjunction with ARRAYFORMULA and without it.
You can have a look to my test Google Sheet
here or to snapshots here with ARRAYFORMULA (column B), without it (column C) and what I'd like to get (column D):
A little step further from pnuts' solution provides the "perfect" result without the "N/A" cells:
=ARRAYFORMULA(IF(A3:A="";"";VLOOKUP(A3:A;KEYS!A1:B;2;FALSE)))
Of course there is a major impact on the performances as the VLOOKUP is run once for every single line in in the second sheet (and this was also why I was trying to use FILTER).
Those performances are quite low even with the currently linked example sheet, which is really skinny.
In Row3 please try:
=ArrayFormula(vlookup(A3:A;KEYS!A$1:B$5;2;0))
you can use a From spreadsheet - On change event trigger to call code like below:
function CopyPasteWastageRows() {
var spreadsheet = SpreadsheetApp.getActive().getSheetByName("<<Sheet-Name>>");
spreadsheet.getRange('Q2').activate();
var currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
spreadsheet.getRange('Q2').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getRange('Q2').activate();
};
Try:
=ARRAYFORMULA(IF(LEN(A3:A); VLOOKUP(A3:A;KEYS!A1:B;2;FALSE);))
That should get the keys, as far as values are entered in col A.

Google Docs - SUMIF - SUM range if single cell contains a string

I'd like to quickly include or exclude an entire range of values in a SUM.
Presently I'm SUMing select cells for a grand total: [E19] =SUM(E13,E20,E30,E45,E55,E70,E80)
These are in turn SUMs of selected ranges:
... [E30] =SUM(E31:E44), [E55] =SUM(E56:E69), ...etc.
One of these ranges I would like to toggle it's inclusion in the Grand Total.
It seemed the best way to do it was this:
[E45] =SUMIF(D45,"☑",E46:E54)
In short, in cell E45 I'd like to SUM E46 to E54 only if D45 contains a ☑.
However Google Doc's SUMIF seems to only work with matched ranges: =SUMIF(D46:D54,"☑",E46:E54)
Is there a way to SUM a range only if a specific value exists in a single cell?
You're right about SUMIF, it allows you to sum values from a range, which meet a certain criteria (on another range of the same length). For example, if you had two columns called "status" and "price", you could use it to sum all the prices for a given status.
What you're trying to do can be done, instead, with the use of the IF function:
=IF(D45="☑";SUM(E46:E54);0)
If the condition specified in the first argument is true, it will return the second argument, that is, the sum. Otherwise, it will return the third argument, 0.
After working through the logic to share the issue I wound up identifying a solution. Rather than trying to force SUMIF to check a single cell against a range. I just nested the 1:1 SUMIF inside my 'Grand SUM': =SUM(E13,E20,E30,SUMIF(D45,"☑",E45),E55,E70,E80).

Resources