Forum Discussion
Function currency conversion
- 1 year ago
You can use Record.Field as below
(sourceCurrency as text, Amount_Currency as number, column as text )=>
let
Source = tbFXRates,
FXRate = Record.Field(Table.SelectRows(Source, each ([Currency] = sourceCurrency )){0},Column),
Conversion = Value.Divide(Amount_Currency,FXRate)
in
Conversion
Use the following code.
Just replace the Source table with your currency rate table
(Currency )=>
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcg0NUtJRMlSK1YlWCg12AbIrgADMdXcKgHNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Currency = _t, #"FX to EUR" = _t]),
#"Filtered Rows" = Table.SelectRows(Source, each ([Currency] = Currency ))[FX to EUR]{0}
in
#"Filtered Rows"
Omid_Motamedise Thank you for quick reply.
This is your code adjusted a little to fit my needs:
(sourceCurrency as text, Amount_Currency as number )=>
let
Source = tbFXRates,
FXRate = Table.SelectRows(Source, each ([Currency] = sourceCurrency ))[FXRate EUR] {0},
Conversion = Value.Divide(Amount_Currency,FXRate)
in
Conversion
There is one addition I would like to add to the code, which I cant figure out. As of now FXRate EUR is hard coded to the function. I would like to be add the column as a parameter so I can adjust the source and target currency as needed. How would I add [FXRate EUR] as a parameter in the function?
- Omid_Motamedise1 year agoSuper User
You can use Record.Field as below
(sourceCurrency as text, Amount_Currency as number, column as text )=>
let
Source = tbFXRates,
FXRate = Record.Field(Table.SelectRows(Source, each ([Currency] = sourceCurrency )){0},Column),
Conversion = Value.Divide(Amount_Currency,FXRate)
in
Conversion