Dynamically convert currency - google-sheets

I have a column of values in varying currencies. I want to create a column that automatically detects the currency of a given value and converts that to GPB (or any other given currency).
I have the following formula for querying the exchange rate:
=INDEX(GoogleFinance("eurgbp","price",date(2014,9,15)),2,2)
However this requires that you specify the currency you are converting from. I want this to be dynamic, because my list of currencies varies.

You can return a text string representation of a formatted value with:
=TO_TEXT(A1)
So if you have the value 35 formatted as British Pound Sterling, the formula will return the string:
£35.00
Now you can match that string with a lookup table (probably using REGEXMATCH) to return the string required for GoogleFinance(). The trouble is that the native format of, say, the US dollar, is exactly the same as, say, the Australian dollar. However, you can set your own custom number formats (eg with USD or AUD appended) that will be carried through to the TO_TEXT function.
So you would probably need to describe all your possible currency formats to arrive at a more specific solution.

Sounds like you'll need to come up with some kind of encoding for the currency column values. For example:
Currency
----------
USD, 10254 # $102.54
RMB, 1010 # ¥101.0
You'd then need to parse that column value somehow in order to determine the currency type. Or you could have two columns. One for currency type and the other for currency value:
Type Currency
---- --------
USD 10254 # $102.54
RMB 1010 # ¥101.0
By the way, the currency columns are integers so you don't have to use floating point math which is a nice thing to avoid in my experience.

As AdamL mentioned, you need to check if there are currencies with the same symbols in your list of data.
If not, you can do the following:
Amt Text Amt Symbol
=========================================
(data) =TO_TEXT(A2) =left(B2,FIND(REGEXEXTRACT(B2,"[0-9\.\,]"),B2)-1)
This will get your currency symbol from the column A. The formula is finding the first occurrence of something numeric (including . and ,) and then you just take what is on the left of it to obtain the currency.
Then you need a table for each symbol to its ISO 3 letter code so you can use Google Finance to obtain the FX, something like:
Symbol ISO Ccy
======================================
$ USD
£ GBP
€ EUR
Then you can get the ISO ccy by using VLOOKUP and continue the formulas above, here I did the FX for GBP
Amt Symbol FX Convert Amt
===================================================================================================
(formula above) =IF(D2="GBP",1,INDEX(GoogleFinance(D2&"GBP","price",<SOMEDATE>),2,2)) =E2*A2
I saved an example here.

Related

How to use LAMBDA with GOOGLEFINANCE to perform currency conversions in an array?

I'm trying to write a formula that checks the currency of a stock position and performs a currency conversion if it is anything other than USD. I'd like to make column F into an array but the GOOGLEFINANCE formula doesn't work with the arrayformula. So I've tried using LAMBDA functions with BYROW and MAP but without success.
Column C lists the currency.
Column E lists the entry price of a stock position in that currency.
Column F uses the GOOGLEFINANCE formula to perform currency conversion and display the entry price in USD. (If the currency is pence (GBX), convert as GBP to USD then divide by 100. If the currency is USD, no conversion will be performed. For all other currencies, convert to USD.)
Column G is my attempt to do what column F does but as an arrayformula.
Column H is my attempt to do what column F does using the LAMBDA function with BYROW.
Yellow cells contain formula. Blue cells are manually inputted data.
I appreciate anyone who can take a look at my spreadsheet (linked below) and see what's the best solution for this. Sheet 2 is editable.
https://docs.google.com/spreadsheets/d/1JWkgH2Nf7CFI0Nh9H2-qEMRcwd8iMz7nxebuauplFiE/edit#gid=1126538379
Thanks!
J
added formula to your sheet:
=MAP(C2:C,E2:E,LAMBDA(cx,dx,IF(cx="",,ROUND(IFS(cx="GBX",(GOOGLEFINANCE("GBPUSD")*dx)/100,cx="USD",dx,LEN(cx),GOOGLEFINANCE(cx&"USD")*dx),2))))
-

How to use if-else in google sheets with currency?

I have an issue where I am trying to make a comparison between values to see if A contains value then use that value and if B contains the value then use that value, something like this:
My goal is that when I have resell pris (SEK) value, then I should just =SUM(O6-I6) in Totala profit but if I have in EURO then I want to convert the currency from euro to todays currency in SEK and calculate that for totala profit, meaning something like (100€ * swedish currency) - value in totala profit e.g. 1000.
My question is, is it possible to do that using google sheet? if so, how can I use the if else statement for that?
Expected:
Should take Resell pris SEK/EUR - totala profit depending on where we have the value. If we have in SEK then we do Resell pris SEK - Totala profit and if we have EURO then convert to SEK and then - totala profit.
Actual:
I only managed to make it work if there is a value in Resell pris (SEK)
Use if() and regexmatch(), like this:
=(O6 - I6) * if( regexmatch(to_text(O6), "(?i)EUR|€"), R$1, 1 )
...where cell R1 gets the exchange rate with googlefinance(), like this:
=googlefinance("EURSEK")

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

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

GoogleFinance - Remove USD Symbol

Using google spreadsheets to display currency data, with USD as primary field for formula: =LEFT(V10*GoogleFinance("currency:USDEUR"),5)
I cannot figure out how to remove the the USD Symbol ($) from not show up for the additional currencies. It makes no sense to have the **$**xxx being displayed on non-USD data.
I have tried doing Format -> Numbers but none of those options resolve this issue.
The number formats are not working since the LEFT function is converting the value to text. Does this formula work instead:
=SUBSTITUTE(LEFT(V10*GoogleFinance("currency:USDEUR"),5),"$","")
Highlight the cells you want to change. Go to Format --> Number --> More Formats --> Custom number format. Highlight the "$" and delete it (delete the quotes and dollar sign both). Click apply. I have attached before and after pictures.

Parsing currency into a number in Spoon CSV Text Input

This seems like it should be simple.
I have a CSV file with multiple currency values (so I'd like to avoid writing a bunch of string-manipulation steps if it can be avoided), and I was excited to see that the CSV File Input step has fields like Currency Separator, decimal symbol, grouping symbol (and mine are the default "$", ".", and ",", respectively).
The documentation describes these as for:
Currency Used to interpret numbers like $10,000.00 or E5.000,00
Decimal A decimal point can be a "." (10;000.00) or "," (5.000,00)
Grouping A grouping can be a dot "," (10;000.00) or "." (5.000,00)
(http://wiki.pentaho.com/display/EAI/Text+File+Input)
But as of the current production version (4.4)... these settings do not seem to have an effect.
Has anyone had success with number masks or similar such that a string like "$10,000,238.48" can yield a number that can be pushed into a database? Anything I do is either "Unparsable" in the text input or "truncated field" error at the insert...
When I do a get fields on a text input step with your example number in it, it sets Currency, Decimal, and Group to '$', '.', ',' respectively, and it reads your number just fine. It also sets a Format string of '$#,##0.00;($#,##0.00)', which it seems is the key piece. The text file input step will examine as many rows as you specify from a CSV and guess the formats for each column.
Here is PDI's number formatting table:
Number Formatting Table
If you have different currency formats mixed in the same column, I would use a UDJE step and this answer:
Parsing a Currency string in Java
Or a JavaScript Step and this answer:
Convert Currency string with JavaScript
to strip out all non digit and non decimal point characters, then pass it through a Select Values step. Note, that this will be very tricky if you have mixed decimal separators in the input column.

Resources