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

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")

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 do SUM + vertical SPLIT to receive the value of a string in the format datetime "YYYY/MM/DD - HH:MM:SS"?

My strings are in this format:
COLUMN Z
2022/03/11 - 16:36:01
2022/03/11 - 16:29:41
2022/03/11 - 16:34:21
I want to convert them to VALUE() to find out if they are datetime greater or less than NOW(), if the values in the column were formatted as datetime, I could do it like this:
=ARRAYFORMULA(VALUE(Z1:Z)<VALUE(NOW()))
But they're not, so to convert this type of string, the method I use is:
COLUMN AA
=SUM(SPLIT(Z1," - "))<VALUE(NOW())
=SUM(SPLIT(Z2," - "))<VALUE(NOW())
=SUM(SPLIT(Z3," - "))<VALUE(NOW())
But I couldn't make SUM accept ARRAYFORMULA vertically, SPLIT accepts but SUM doesn't.
My failed attempt was:
=ARRAYFORMULA(SUM(SPLIT(Z1:Z," - "))<VALUE(NOW()))
How should I proceed?
You can use MMult like this:
=ArrayFormula(if(Z1:Z="",,MMult(--iferror(split(Z1:Z,"-")),{1;1})<now()))

Taking Average of Money in SQL/SQLPro

I am working on a dataset, and I am having trouble trying to calculate the average of a column with dollar currencies in it. All the values, for example, are listed in the format of $12.00, $5.43, $1,234.00.....
Whenever I use the code below, it returns a value of 0 as the avg. In the same vein, it does the same thing for the SUM command as well.
SELECT AVG(bill_amount) FROM Trips WHERE trip_date >= '08/13/13';
Is there something wrong with the code I am using, because I think it's right.
You would appear to be storing values in the bill_amount column as text rather than as a number. You can convert them to a number and then use average. Something like this:
select avg(cast(case when substr(bill_amount, 1, 1) between '0' and '9' then bill_amount
else substr(bill_amount, 2)
end) as decimal(18, 4))

How to trim the decimal part from money field

I have a View() with a link to make a payment. Link looks something like this
Pay Now
My problem is Model.Amount has the amount format like this 20.00 or 100.00 because the DataType is money and its adding extra zero's.
I need to remove the '.' so it reads 2000 or 10000.
How can I achieve that?

Dynamically convert currency

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.

Resources