ArrayFormula with VlookupS If one is blank then use second Vlookup in Google Sheets - google-sheets-formula

I'm trying to use Vlookup in a Google Sheet using an ID to match 2 separate tables. If there is no match in the first table, then I am telling the code to search for it in the second table. The lookup value, and 2 tables are all in different sheets and it doesnt work but I am able to get another test to work when they are all on the same sheet so I am not sure why that is.
For example this works
arrayformula(IFERROR(if(vlookup(A2:A,D2:E,2,FALSE)<>"",vlookup(A2:A,D2:E,2,FALSE),vlookup(A2:A,G2:H,2,FALSE))))
ID
Vlookup
ID
Vlookup value
ID
Vlookup value
1
One
1
One
1
2
Two
2
2
Two
3
Three
3
Three
3
4
Four
4
4
Four
5
This Full Formula fails
Arrayformula(IFERROR(IF(vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE)<>"",vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE),vlookup($B$2:$B,'Sheet2'!$A$1:$N,4,FALSE))))
I'm not sure how to moidfy my formula, which works in individual parts and together it matches data in Sheet1! but not on Sheet 2! based on my tests.
Testing Results
Arrayformula(IFERROR(IF(vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE) --> Vlookkup matches Sheet1! data also
Arrayformula(vlookup($B$2:$B,'Sheet2'!$A$1:$N,4,FALSE) -->matches Sheet2! data
Modify the second part of the data to "False"
Arrayformula(IFERROR(IF(vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE)<>"",vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE),"False"))))
Result: Anything that does not match in either Sheet 1 or Sheet 2 says "False". But a match in Sheet 1 works and a match in Sheet 2 shows blank.
Modifying the IF statements to make consistent did not work either
Arrayformula(IFERROR(IF(vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE)<>"",vlookup($B$2:$B,Sheet1!$A$3:$I,4,FALSE),
IF(vlookup($B$2:$B,Sheet2!$A$1:$N,4,FALSE)<>"",vlookup($B$2:$B,Sheet2!$A$1:$N,4,FALSE),""))))
How can I modify the formula so that it works in unison?

This works
=arrayformula(IFERROR(if(vlookup(A2:A,Sheet1!A1:B5,2,FALSE)<>"",vlookup(A2:A,Sheet1!A1:B5,2,FALSE),vlookup(A2:A,Sheet2!A1:B5,2,FALSE))))
Still unsure if there is another error in the formula above that didn't work as I think it should have worked

Related

Google Sheet Query: Select misses data when there are different data type in a column?

I have a table like this:
a
b
c
1
2
abc
2
3
4.00
note c2 is text while c3 is a number.
When I do
=QUERY(A1:C,"select *")
The result is like
a
b
c
1
2
2
3
4.00
The "text" in C2 has been missed. You can see the live sheet here:
https://docs.google.com/spreadsheets/d/1UOiP1JILUwgyYUsmy5RzQrpGj7opvPEXE46B3xfvHoQ/edit?usp=sharing
How to deal with this issue?
QUERY is very useful, but it has a main limitation: only can handle one kind of data per column. The other data is left as blank. There are usually ways to try to overcome this from inside the QUERY, but I've found them unfruitful. What you can do is just to use:
={A:C}
You can work with filters by its own, but as a step-by-step to adapt the main features of query: If you need to add conditions, use LAMBDA INDEX and FILTER
For example, to check where A is not null:
=LAMBDA(quer,FILTER(quer,INDEX(quer,,1)<>""))({A:C}) --> with INDEX(quer,,1), I've accesed the first column
Where B is more than one cell and less than other:
=LAMBDA(quer,FILTER(quer,INDEX(quer,,2)>D1,INDEX(quer,,2)<D2))({A:C})
For sorting and limiting an amount of items, use SORTN. For example, you want to sort by 3rd column and limit to 5 higher values in that column:
=LAMBDA(quer,SORTN(FILTER(quer,INDEX(quer,,1)<>""),5,1,3,0))({A:C})
Or, to limit to 5 elements without sorting use ARRAY_CONSTRAIN:
=ARRAY_CONSTRAIN(LAMBDA(quer,FILTER(quer,INDEX(quer,,1)<>""))({A:C}),5)
There are other options, you can use REGEXMATCH and other options, and emulate QUERYs functions without missing data. Let me know!
shenkwen,
If you are comfortable with adding an Google App Script in your sheet to give you a custom function, I have a QUERY replacement function that supports all standard SQL SELECT syntax. I don't analyze the column data to try and force to one type based on which is the most common data in the column - so this is not an issue.
The custom function code - is one file and is at:
https://github.com/demmings/gsSQL/tree/main/dist
After you save, you have a new function from your sheet. In your example, the syntax would be
=gsSQL("select a,b,c from testTable", {{"testTable", "F150:H152", 60, true}})
If your data is on a separate tab called 'testTable'(or whatever you want), the second parameter is not required.
I have typed in your example data into my test sheet (see line 150)
https://docs.google.com/spreadsheets/d/1Zmyk7a7u0xvICrxen-c0CdpssrLTkHwYx6XL00Tb1ws/edit?usp=sharing

How use filter formula in Google Sheet with data contains #N/A

For my example, I have 2 columns A,B in Google Sheet
Column A with list of Stocks symbols like AAPL, IBM, etc....
Column B with simple formula of GOOGLEFINANCE(A2,"price")
Sometimes GOOGLEFINANCE returns error and the cells display #N/A. But this is not my issue...
I would like using filter in column B which show all symbols with prices greater than 100 or #N/A
I prefer not using extra column to achieve that
I'm struggling with it and still didn't find the way to get my result
Just note, my issue isn't GOOGLEFINANCE, It's like example to get the #N/A value
My tought was using filter with formula like: =OR(ISNA(B:B), B:B>100)
But it seems it's ignore the #N/A and doesn't show it
Link for example
In my question I tried the formula "=OR(ISNA(B:B), B:B>100)"
But I must know that if Google Sheets "see" cells with N/A on this column - The result is automatically N/A, even if I put the ISNA in the first condition
So to solve it I used a formula like this:
=IF(ISERROR(B:B), TRUE, B:B>100)
I updated the sheet if someone wants to check it

Matching (querying?) criteria with IMPORTRANGE

Forgive me if I am not using the correct terminology, I short of crash-coursed myself in Google sheets a few days ago.
Is there a way that I could using IMPORTRANGE to import a data range from spreadsheet 2 into spreadsheet 1, where the range selected from spreadsheet 2 can be matched against criteria in spreadsheet 1 that corresponds to criteria in spreadsheet 2? I have a specific set of data in spreadsheet 1 that, while the same in content, is not in the same order as spreadsheet 2 (which I don't myself maintain) or spreadsheet 3 (which is maintained by someone other than myself or the person that maintains spreadsheet 2), but am being given access to spreadsheet 2 and spreadsheet 3 data that I didn't previously have.
EXAMPLE:
https://docs.google.com/spreadsheets/d/1ByN9Ju8QiiHTfFgow7lDF4VN-zBRqP1gzpAK73ZRBNg/edit?usp=sharing
You work with IMPORTRANGE content the same way as you do with any range within your spreadsheet. Good practice is to use columns with unique content as ID's for searching, filtering, etc.
If you want put the content of somebody's spreadsheet into yours, you can control it.
For example:
In order to get REGISTRATION number from sheet3
Think of VLOOKUP construction:
=VLOOKUP(key,table with key value on the leftmost column;number of column to take value from,false)
You use vlookup formula that takes name in your table as a key (first parameter of formula), then you must rebuild your importrange to have key in leftmost column.
2nd parameter of VLOOKUP will look like this:
{importrange("Sheet3url";"Sheet!Columnwithname"),importrange("Sheet3url";"Sheet!Columnwithregistration")}
This is your temporary table made of 2 importranges.
You want 2nd column of this construction - which is column with registration.
Whole vlookup looks like this:
=VLOOKUP(key,{importrange("Sheet3url";"Sheet!Columnwithname"),importrange("Sheet3url";"Sheet!Columnwithregistration")},2,false)
It's much easier when key is on the left. If you want to extract SEX and DOB you use:
=VLOOKUP(key,importrange("Sheet3url";"Sheet!Columnsfromname to DOB"),2 and then 3,false)
Beware - using multiple importrange makes your sheet slow.
If you have hundreds of rows, you should wrap it around with arrayformula to work with all rows in one go.
Also you can first importrange somebodys table into your sheet on a side and operate inside your sheet.
It's advised when using big datasets and not that many files.

Google Sheets: Data Validation - Unique row values across multiple columns

Good day,
I have seen from here a solution to control duplicate entries into a single column. A Data validation with this custom formula works well for one column.
I would like to achieve the same effect over multiple columns ... i.e. unique row entries across multiple columns. Take for example below three columns A-C. Only when values {1,2,1} are entered for the second time will the input be rejected.
A B C
1 1 1
1 2 1
1 2 2
2 2 2
1 2 1 X Entry should be rejected.
Is there a quick way to do this using Data Validation - custom formulae?
use custom formula for data validation:
=INDEX(COUNTIF($A$1:$A&"×"&$B$1:$B&"×"&$C$1:$C, $A1&"×"&$B1&"×"&$C1)<2)

OpenOffice Calc move only unique values to new column

I looked around for a bit and didn't see any question quite like the one I have. I have a sheet with over 80k values in column A. What I need, is to remove every occurrence of a duplicate. If the value 5 appears more than once, I don't want the value at all. For example, if I have something like this:
A
1
2
2
3
4
3
I ONLY want the values of 1 and 4, because they only appear once. I'd like every other value deleted, or to have only the values like 1 and 4 appear in another column.
Any help is greatly appreciated.
Work on a copy as the following deletes records from source data. In B1 (adjust 90000 to suit):
=COUNTIF(A$1:A$90000;A1)>1
and copy down to suit. Filter A:B, select 1 for ColumnB and delete the selected rows. Change filter to select All.

Resources