using SWITCH() Formula in Google Sheets using hash-map - google-sheets

In my Google Sheet table, I use SWITCH command to convert a cell from coin symbol -> into coin value.
what I currently do:
=SWITCH(D660,"₪","ILS","$","USD","Ft","HUF","€","EUR","лв","BGN","£","EGP")
this will convert cell D660 from coin symbol (₪/$/Ft/€/лв/£) -> into coin name
here's an example of my data:
where in column E I have the equation above.
what I want to do:
I want to a more generic way, where I have a "hash-map" table in my Settings tab which contains the following table:
coin_symbol
coin_name
₪
ILS
$
USD
Ft
HUF
€
EUR
лв
BGN
£
EGP
and now I want the =SWITCH(D660,...) to use the table instead of hard coding inserting the conversion table
.
I'm struggling on this one, I tried stuffs like
=SWITCH(D660,A1:A10,B1:B10) or involving ARRAYFORMULA somewhere but nothing worked.
anyone have a suggestion how to implement that?

You can use VLOOKUP()
In table with the coins symbols and value as you described ( where symbols is column A and name column B)
=VLOOKUP([SYMBOL];[A1:B6];2;FALSE)
Where:
Symbol is the symbol you want to replace ( you can use cell reference );
A1:B6 is the table you want to look in;
2 is the column in wich you take the value;
False as the values are not ordered by a number, just use false.
/!\ depending on your locatioon the ; in my formula might have to be replaced by ,
Here's an example you could use

Related

Combining a Cell Reference and Wildcard as Criterion in Google Sheets CountIf Formula

I'm struggling with writing the proper syntax for this formula in Google Sheets. In one sheet called Game Log, in the H column I have data that can be a range of names (1 - 10 names per row). I'm trying to construct a COUNTIF statement that would search for the name in all the rows for that column. There can be several other names in the same column so I need to use the wildcard * to find any occurrence of the name in each row. So for example, the current code below would count all occurrence of Adam in the rows.
=COUNTIF('Game Log'!H3:H102, "*Adam*")
What I would like to do is replace the hard codes "Adam" with a cell reference (in this case B2). Is it possible to combine that cell reference with the wild card? The know the code below doesn't work (as it would return text counting occurrences of B2), but is something like this possible?
=COUNTIF('Game Log'!H3:H102, "*B2*")
Have you tried something like this?
=COUNTIF('Game Log'!H3:H102, "*" & B2 & "*")
That ought to look for any string value, followed by the cell value, followed again by any string value. It's essentially just performing separate checks, in sequence, which allows you to search for different value types (in this case string wildcard + cell value + string wildcard).

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"

ArrayFormula, RegexExtract, and Join in Google Sheets

I have a data set wherein emails are populated. I would like to list all the surnames extracted in the emails per cell and will be all joined to a one single cell but I want to put a separator or delimeter to the emails obtaine per cell.
Here is the data set:
A
B
john.smith#gmail.com, jane.doe#gmail.com
UPDATE
john.smith#gmail.com
CLOSE
And here is the formula to extract
=ARRAYFORMULA(
PROPER(
REGEXEXTRACT(
A:A,
REGEXREPLACE(
A:A,
"(\w+)#","($1)#"
)
)
)
)
This initially yields the ff:
C
D
Smith
Doe
Smith
I would like to use JOIN() inside the ARRAYFORMULA() but it is not working as I seem to think it would since it outputs an error that it only accepts one row or one column of data. My initial understanding of ARRAYFORMULA() is that it iterates through the course of the data, so I thought it will JOIN() first, and then move on to the next element/row but I guess it doesn't work that way. I can use FLATTEN() but I want to have delimiters or separators in between the row elements. I need help in obtaining my intended final result which will look like this:
UPDATE:
Smith
Doe
CLOSE:
Smith
All are located in one cell, C1. UPDATE and CLOSE are from column B.
EDIT: I would like to clarify that the email entries in column A are dynamic and maybe more than two.
I think this will work:
=arrayformula(flatten(if(A2:A<>"",regexreplace(trim(split(B2:B&":"&char(9999)&regexreplace(Proper(A2:A),"#[\w\.]+,\ ?|#.*",char(9999)&" "),char(9999))),".*\.",),)))
NOTES:
Proper(A2:A) changes the capitalisation.
The regexreplace "#[\w\.]+,\ ?|#.*" finds:
# symbol...
then any number of A-Z, a-z, 0-9, _ [using \w] or . [using \.]
then a comma
then 'optionally' a space \ [the optional bit is ?]
or [using |], the # symbol then an number of characters [using .*]
The result is replaced with a character that you won't expect to have in your text - char(9999) which is a pencil icon, and a trailing space (used later on when the flatten keeps a gap between lines). The purpose is to get all of the 'name.surname' and 'nameonly' values in front of any # symbol and separate them with char(9999).
Then infront of the regexreplace is B2:B&":"&char(9999)& which gets the value from column B, the : chanracter and char(9999).
The split() function then separates then into columns. Trim() is used to get rid of spaces in front of names that don't contain ..
The next regexreplace() function deletes anything before, and including . to keep surname or name without ..
The if(A2:A<>"" only process rows where there is a value in col A. The arrayformula() function is required to cascade the formula down the sheet.
I didn't output the results in a single cell, but it looks like you've sorted that with textjoin.
Here's my version of getting the results into a single cell.
=arrayformula(textjoin(char(10),1,if(A2:A<>"",REGEXREPLACE(B2:B&":"&char(10)&regexreplace(Proper(A2:A),"#[\w\.]+,\ ?|#.*",char(10)),".*\.",),)))
Assuming that your A:A cells will always contain only contiguous email addresses separated by commas, you could place this in, say, C1 (being sure that both Columns C and D are otherwise empty beforehand):
=TRANSPOSE(FILTER({B:B,IFERROR(REGEXEXTRACT(SPLIT(PROPER(A:A),","),"([^\.]+)#"))},A:A<>""))
If this produces the desired result and you'd like to know how it works, report back. The first step, however, is to make sure it works as expected.
use:
=INDEX(REGEXREPLACE(TRIM(QUERY(FLATTEN(QUERY(TRANSPOSE({{B1; IF(B2:B="",,"×"&B2:B)},
PROPER(REGEXEXTRACT(A:A, REGEXREPLACE(A:A, "(\w+)#", "($1)#")))})
,,9^9)),,9^9)), " |×", CHAR(10)))

Google Sheets: How do I create an array from a range, adding a column with a constant literal value in every row?

I want to make an array with several columns. The second and subsequent columns are specified as a range pulled from another sheet. The first column is a static constant, that is, every cell in the first column should have the very same literal string value, say 'foo'. I can't find the correct syntax. I'd have thought something like this would work:
={"foo", 'Other Sheet'!C2:F}
but I get "Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 1. Actual: 999." Clearly "foo" needs to be "expanded" to a column with lots of rows. How do I do it, and where are tricks like this documented?
Maybe the answer to this question would give a start: How do I create an array containing a single column, every cell containing "foo", with the number of columns specified by a different range?
Here is an editable sheet illustrating the problem and the desired solution:
https://docs.google.com/spreadsheets/d/17myzKVFN3SDQuubWNdP-dFAbdvdlRbZFkjRpLi2Fas8/edit?usp=sharing
The exact question is this: what formula can I put in cell B9 of Sheet1 to get the current appearance of Sheet1? Notice that I don't know in advance how many rows there are in 'Other Sheet'. It's OK to assume that all rows of Other Sheet have a nonblank value in column C.
You can loop with an arrayformula and assign them to the first column, ending the array with the same size:
={ARRAYFORMULA(if(len('Other Sheet'!C2:C),"foo",)),'Other Sheet'!C2:F}
Side note: that between the {}, if you put a comma ({expr1 , expr2}), the value will be side by side, and if you put a semicolon ({expr1 ; expr2}), the values will be one above the other.
You can use QUERY for that:
=QUERY('Other Sheet'!C2:F, "select 'foo',C,D,E,F where C is not null")
If you want to remove the 'foo' column header, you can use:
=QUERY('Other Sheet'!C2:F, "select 'foo',C,D,E,F where C is not null label 'foo' ''")

how to create "" for a column containging duplicate values

So I have a worksheet with multiple columns and one of the columns contains description of the product.
I have multiple lines of apples and multiple lines or orange.
Is there a forumla that can display only one cell with the product description with apples, oranges, and leave rest of the duplicates blank ("").
I wouldn't really recommend using blanks there. Your original data setup is perfect for a flat file and makes performing calculations like Countif/s, Sumif/s, etc really easy.
If you absolutely must change it, you could use column E as a helper with this formula starting in cell E2 and copied down (note, this formula requires that the data be sorted by Product as shown in your example):
=IF(B2=B1,"",B2)
Then copy the helper column -> select B2 -> right-click -> paste special -> values
And delete the helper column.

Resources