Replace NA with an empty string - google-sheets

I have a long google-sheet formula, how can I wrap it with a condition so N/A only would be replaced with an empty string?
If know =IFNA(a, "",a) but I don't want to repeat the long formula (a).

IFNA(value, value_if_na) expects 2 parameters:
value: The value to check if it is a #N/A error.
value_if_na: The value to return if the first argument is an #N/A error.
Your formula should be this: =IFNA(a, "")

Related

How do I get the column letter of a single row where a particular value equals a test value?

I need to get the letter of the column that has a value in a given row that matches a given value in Google Sheets, assuming that no values in the row are duplicates.
For example, in the above screenshot, if the row is the first row, and the test value is Jun, the formula will return H.
Kind of meta. Appreciate any help.
Answer
The following formula should produce the behaviour you desire:
=REGEXREPLACE(ADDRESS(1,MATCH("Jun",A1:1),4),"[1-9]*",)
Explanation
The =MATCH formula returns the position of the item in a range which has a specified value. In this case, the specified value is "Jun" and the range is A1:1.
=ADDRESS returns the A1 notation of a row and column specified by its number. In this case, the row is 1 and the column is whichever number is returned by the =MATCH. The 4 is there so that =ADDRESS returns H1 instead of $H$1 (absolute reference is its default).
=REGEXREPLACE looks through a string for a specified pattern and replaces that portion of the string with another string. In this case, the pattern to search for is any number. The last argument of =REGEXREPLACE is blank so it simply removes all numbers from the string.
What is left is the letter of the column where the value is found.
Functions Used:
=MATCH
=ADDRESS
=REGEXREPLACE
Now that Google Sheets has added Named Functions, there is an easier way to do this.
To use named functions, go to Data -> Σ Named Functions. A sidebar will pop up. At the bottom use "Add new function" to create a new named function.
I created two functions to do this:
First, COL_CHAR which will take a column reference and return its letter
Second, ALPHA_CHAR which takes a numeric input and converts it to letters. I made this one recursive, so if it's an n-letter column name, it will keep calling itself until it gets the full name.
COL_CHAR just converts the referenced column to a column number and passes that to ALPHA_CHAR. It's formula is:
=ALPHA_CHAR( column(cell) )
where cell is an Argument placeholder. Make sure to add that to the argument placeholder list in the sidebar.
Here is the (recursive) formula for ALPHA_CHAR:
=IF( num > 26, ALPHA_CHAR( INT( num / 26 ) ), "") & CHAR( CODE("A") - 1 + MOD( num, 26 ) )
where num is an Argument placeholder.
By making this recursive, even if Google Sheets expands to allow 4-letter (or more) columns in the future, it will keep iterating through every letter regardless of how many there is.
Then, to get the letter of a column in the spreadsheet, you just call COL_CHAR and pass the cell in the column you want, for example:
= COL_CHAR(BK1)
Will return the string "BK"

Google Finance doesn't recognise my date field and is returning an error message

I'm having an issue with the following formula in google sheets:
=IFS(F2<> "EUR", E2*GOOGLEFINANCE("Currency:"&F2&$G$1,"price", H2), F2 = "EUR", E2)
H2 is a cell which holds a date. I am trying to get a formula I can use for multiple different dates.
I got the following error message:
Function MULTIPLY parameter 2 expects number values. But 'Date' is a text and cannot be coerced to a number.
According to my research the formula has these constraints:
=GOOGLEFINANCE("Currency:USDGBP", "price", DATE(YYYY,MM,DD), DATE(YYYY,MM,DD)
Where the first nested DATE function is the start date, and the second DATE function is the end date. And they are optional.
I tried Date(H2) and I got this error message:
Wrong number of arguments to DATE. Expected 3 arguments, but received 1 arguments.
Thank you in advance!
any time GoogleFinance() reutrns a historical array, you need to INDEX() it to get just the single answer.
It's almost always the second row and second column of the array that you want.
So:
=INDEX(Goooglefinance(.... ), 2, 2)
I've tested your function and the error Function MULTIPLY parameter 2 expects number values. But 'Date' is a text and cannot be coerced to a number is due to this part E2*GOOGLEFINANCE("Currency:"&F2&$G$1,"price", H2) in your IFS function.
The return value of the GOOGLEFINANCE("Currency:"&F2&$G$1,"price", H2) is an array (it contains strings and numbers) and multiplying it to E2 value is not possible. Also, if running GOOGLEFINANCE("Currency:"&F2&$G$1,"price", H2) alone works just fine, then the H2 (the date cell) isn't the main cause of the error.
RECOMMENDED SOLUTION:
I've checked on how to only return price instead of an array on GOOGLEFINANCE function and stumbled upon an answer from How can I get GOOGLEFINANCE to return only the historical price of a stock and not an array?.
Instead, you can try this function below:
=IFS(F2<>"EUR", min(GoogleFinance("Currency:"&F2&$G$1, "PRICE", H2))*E2, F2 = "EUR",E2)
Here's a sample test on my end:

Google sheets, remove characters inside a string

I have a value in a cell like this: '2016-Week 44'
I would like to the output as '2016-44', so how could I do this?
Edit: so I have values like this
'2016-Week 44'
'2016-Week 45'
'2016-December'
If the value does not contain 'week', I want it to return NA or error
I'd solve it with regular expressions. Assuming the original values are in column A, this would be the expression:
=IF(REGEXMATCH(A1,"(?i)week"),REGEXREPLACE(A1,"([\d])\-\w+ ([\d])","$1-$2"),"empty")
(?i)week → Pre-condition: empty if not string "week", case insensitive
([\d]) → First numeric Group ($1)
\-\w+ →Character string (-) and not used text (if the word "week" does not appear the function is not processed by the first conditional)
([\d]) → Second numeric group ($2)
try simple:
=SUBSTITUTE(A1; "Week "; )

Keep result of SPLIT() as string instead of number for VLOOKUP()

In Google Sheets, I have this formula:
=ARRAYFORMULA( VLOOKUP( SPLIT(F2,", "), A2:B8, 2, FALSE) )
The intent is to take the comma-delimited string in cell F2 and find all values associated with the pieces. This works correctly, except when one of the pieces of the string looks like a number. For example, if F2 has the text a, 1.2, 1.2.3 then VLOOKUP will look for a as a string, and for 1.2.3 as a string, but will look for 1.2 as a number.
How can I coerce the result of SPLIT so that each piece remains a string?
I have a public copy of a test spreadsheet viewable here:
https://docs.google.com/spreadsheets/d/115WmV0vfXfaRgT0fVifJo86od3irZQy5gB3l-g6c7Ts/edit?usp=sharing
As background information, VLOOKUP treats strings and numbers differently. For example, given this table (where the formulae are shown for the first column):
A B
1 ="1.2" STR
2 =1.2 NUM
4 =VLOOKUP("1.2",A1:B2,2,0)
5 =VLOOKUP(1.2,A1:B2,2,0)
...the value shown in A4 will be "STR", and the value shown in A5 will be "NUM".
You can CONCAT a number with an empty string to convert it into its equivalent string representation.
CONCAT(1.2,"") yields "1.2"
To do this for every value, you must wrap the CONCAT() call in ARRAYFORMULA():
=ARRAYFORMULA(CONCAT(SPLIT(F2,", "),""))
The final formula thus becomes:
=TRANSPOSE(ARRAYFORMULA(VLOOKUP(ARRAYFORMULA(CONCAT(SPLIT(F2,", "),"")),A2:B8,2,FALSE)))

How does COUNTA function works (google spreesheet)?

In a google spreadsheet I have the columns A and B populated with some data, then I have this formula to count the values in A if B=1:
=COUNTA(FILTER(A:A;B:B=1))
Problem is that the formula is counting 1 match even if there is no value matching the criteria.
This is the spreadsheet: https://docs.google.com/spreadsheet/ccc?key=0Ak9RViY8FJE5dF9PN3F2ZVFsenk3TG1LZkZjS0d4MHc#gid=0
Thats because the filter results in Error - showing the count 1 which is error...please try
=COUNTA(IFERROR(FILTER(A1:A3,B1:B3=1),""))
The error is being counted and the other result replaces the error with "" which would also return 1. If you want an empty filter result to return zero simply omit the second argument...
=COUNTA(IFERROR(FILTER(A1:A3,B1:B3=1)))

Resources