Google sheets - How to add a variable to a formula using concatenation

In this post I will use the example of getting currency rates from the Google finance API. For this we will do a conversion between two currencies, EUR and USD. The current price for 1 EUR in USD is 1,09.

A B
1 Currency Rate
2 EUR 1,09

If we were to put this into a formula, B2 could be written as:

GOOGLEFINANCE("CURRENCY:EURUSD")

We simply provide the Google finance API with a string that contains "CURRENCY:" and then the two currencies we want an exchange rate between. If we wanted to get the values of A2 and put that within the formula we could do the following:

GOOGLEFINANCE(CONCATENATE("CURRENCY:",A2,"USD"))

This will Concatenate the string, which means it will result in "CURRENCYEURUSD". We have simply used the value of the cell A2 as a Variable for a concatenation which then is used for the Google finance call. Alternatively you can use &symbols:

=GOOGLEFINANCE("CURRENCY:" & A2 & "USD")

The above works the same as using CONCATENATE.

I hope you found this helpful, if you did please leave a comment down below!