Lookup Dates and Return Currency Rates in Google Sheets

Published on

To look up dates and return currency exchange rates from Google Finance, we can use a combination formula in Google Sheets. This array formula involves the GOOGLEFINANCE, QUERY, and VLOOKUP functions, allowing us to retrieve single or multiple currency rates.

Google Finance provides international exchange rates, along with real-time market quotes and other financial data.

Please refer to the screenshot below. In it, you can see various dates in column A and their corresponding exchange rates in column B.

Lookup dates and return currency exchange rates in an array

The conversion rate shown is from USD to INR, but you can choose your preferred currencies. There is an array formula in cell B2 that returns these exchange rates. Let’s now dive into the formula and its explanation.

Lookup Dates and Return Currency Rates: Formula and Overview

Here is the formula used in cell B2 to look up dates in A2:A and return currency exchange rates from Google Finance in B2:B:

=ArrayFormula(IFNA(VLOOKUP(
   A2:A, 
   QUERY(
      GOOGLEFINANCE(
         "CURRENCY:USDINR", "PRICE", MIN(A2:A)-5, MAX(A2:A)+5, "DAILY"
      ), 
      "SELECT TODATE(Col1), Col2", 1
   ), 2, 0
)))

When using this formula, replace A2:A with your specific date range reference and USDINR with your required currency codes.

The currency conversion is from USD to INR. To find other currency codes, please check out https://en.wikipedia.org/wiki/ISO_4217.

It’s also important to note the dates specified. Make sure they are not too distant; dates spanning several years may cause issues. Dates within 2 to 3 years are acceptable. Otherwise, the formula may fail or slow down. You will understand the reason in the formula explanation below.

Here is the role of each function in the formula for looking up dates and returning exchange rates.

Formula Explanation

There are three key functions in use: GOOGLEFINANCE, QUERY, and VLOOKUP. Here are their roles:

Part 1: GOOGLEFINANCE

GOOGLEFINANCE("CURRENCY:USDINR", "PRICE", MIN(A2:A)-5, MAX(A2:A)+5, "DAILY")

This formula fetches daily currency exchange rates from the Google Finance website, covering a range from the minimum date minus 5 days to the maximum date plus 5 days specified in column A.

Google Finance formula to lookup dates and return currency exchange rates

For example, with the sample data, the minimum date is 15/07/2023, and the maximum date is 15/03/2024. Therefore, the formula retrieves currency exchange rates from 10/07/2023 to 20/03/2024. The additional width ensures that we capture all the required information, as GOOGLEFINANCE may sometimes skip some dates at the beginning and end.

The formula returns a two-column array with timestamps in one column and exchange rates in the other. The number of rows in this data will depend on the minimum and maximum dates in column A. Therefore, using distant dates that span several years may slow down performance.

Since we cannot look up dates directly in the timestamp column, we need to convert the timestamps to dates. The following QUERY handles that.

Part 2: QUERY

QUERY(…,"SELECT TODATE(Col1), Col2", 1)

The SELECT clause selects the columns to return; in this case, it’s column 1 and column 2. The TODATE scalar function converts the timestamps in column 1 to dates, so the output will be a date column and a currency exchange rate column.

Part 3: VLOOKUP

VLOOKUP(A2:A, …, 2, 0)

The VLOOKUP function searches for the dates in A2:A within the first column of the QUERY result and returns the exchange rates from the second column.

This way, we can look up dates and return currency exchange rates in Google Sheets.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Marking Case-Sensitive Unique Values in Excel

Marking case-sensitive unique values provides several benefits compared to merely extracting them in an...

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

More like this

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

4 COMMENTS

  1. Prashanth, your formula works awesomely! The formatting issue is with the single quotes getting converted to double quotes in the end.. after col1 and col2, it is not double quotes – it should be 2 single quotes.

    =ArrayFormula(if(len(A2:A),(VLOOKUP(A2:A,query(GOOGLEFINANCE(“CURRENCY:GBPUSD”, “price”, DATE(2017,12,1), DATE(2017,12,31), “DAILY”),“Select Col1, Col2 label Col1 '', Col2 '' format Col1 ‘dd-mm-yyyy’”),2)),””))

    You saved me a bunch of time in doing this – thank you!

    • Hi, Kannan,

      Welcome!

      You are absolutely right! It’s single quote twice in Query labeling to null it. I did use that in my formula. But the formatting makes it looks like a double quote. I will update my tutorial to specify that.

      Thanks.

  2. Thanks for the article but every time I try your formula adjusted for GBPUSD I get a parsing error. What I am trying to achieve is the following.

    In sheet “Stocks” I need to refer to a date (say in cell A3) and lookup the corresponding Fx rate for GBPUSD and return this rate in cell B3

    =ArrayFormula(if(len(A2:A),(VLOOKUP(A2:A,query(GOOGLEFINANCE(“CURRENCY:GBPUSD”, “price”, DATE(2017,12,1), DATE(2017,12,31), “DAILY”),“Select Col1, Col2 label Col1 ”, Col2 ” format Col1 ‘dd-mm-yyyy’”),2)),””))

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.