@lumarseg

Currency tracking using ETL

Project Info

  • Category Business Inteligence
  • Software Power BI Desktop
  • Date 8/6/2023

Project Description

The objective of this project is to develop a historical viewer of the dollar exchange rate, aiming to serve as a valuable tool for enhancing people's financial education. Rather than presenting a step-by-step guide, this document provides a narrative of the project's development process. At the end, a link to download the completed project will be provided.

Project development

To acquire the necessary data for this project, we will be using two sources: the dollar buying exchange rate and the dollar selling exchange rate. These data can be found on the official website of the Central Bank of Costa Rica at the following URL: https://www.bccr.fi.cr/indicadores-economicos

To access the dataset for our exercise, we will navigate to the “Most consulted indicators / Exchange rates” section on the economic indicators page. This will lead us to the specific page containing the required data, which can be accessed at the following address: https://www.bccr.fi.cr/indicadores-economicos/tipos-de-cambio.

Once on the page, we will carefully select the options that correspond to our project’s needs. After opening the selected options, a new page will appear, and we will copy its URL to ensure accurate data retrieval. For your convenience, the addresses of the selected data sources are listed in the table below:

DATASET URL
El tipo de cambio de compra del dólar
https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20367
El tipo de cambio de venta del dólar
https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20370

The completion of this project will provide an informative historical viewer of the dollar exchange rate, which will greatly benefit individuals seeking to expand their financial knowledge.

Data Extract Process

To begin the data extraction process, we will utilize Power BI Desktop, a free application that can be downloaded from the “Microsoft Store“. After opening the application, we proceed to save our project, giving it a suitable name such as “Currency_tracking_demo.pbix“.

Next, we embark on the ETL (Extract, Transform, Load) process by extracting data from the Central Bank of Costa Rica’s website. To achieve this, we navigate through the following menu path: “Home / Data / Get Data.” Within the “Get Data” option, Power BI provides various choices for data extraction. The one we need is located in the “Others” group and is aptly named “web.” Alternatively, you can use the search function and input the keyword “web” to quickly locate the required option. Clicking on “web” will prompt you to press the “Connect” button.

Our initial focus will be on the data related to the dollar buying exchange rate. When prompted, enter the URL for the dollar buying exchange rate data (https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20367) and then click “OK.”

Power BI will initiate an analysis of the provided URL and, after a brief moment, display a list of tables. We will carefully examine the suggested tables and select the one that closely resembles the data distribution in a columnar format, based on the “Web View” perspective. Once the appropriate table is identified, we proceed to load it into Power BI by clicking the “Load” button.

Later on, we will repeat the same process to extract the selling exchange rate data (https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20370)

Data Transform Process

Continuing with the Data Transformation process, we will begin by accessing the “Power Query Editor” through the menu path “Home / Queries / Transform Data.” Upon opening the editor, the datasets previously extracted from the Central Bank of Costa Rica’s website will be displayed on the left side of the screen, each assigned a name by Power BI. We will proceed to rename them as “Buying Exchange Rate” and “Selling Exchange Rate” for clarity.

Next, we will initiate the data transformation for both queries by following a series of steps. The steps will list as they are executed as “Applied Steps” on the right side of the window. Let’s start with the data related to the buying exchange rate.

  • Step 1: We will designate the first row as column headers. Since the first row contains information about the capture year, this step will allow us to name the columns accordingly, based on the corresponding years.
  • Step 2: The currency exchange rate data is currently in text format after being extracted from the dataset. Our next task is to convert this data into numerical format.
  • Step 3: To achieve the desired structure with two columns – the exchange rate date and the exchange rate value – we will pivot the data. By selecting the date column and choosing “Unpivot Other Columns” from the right-click menu, we will effectively reduce the columns representing years to just two: “Attribute” for the year and “Value” for the exchange rate.
  • Step 4: We will merge the columns containing dates and years to create a single column with the complete date format “Day Month Year.”
  • Step 5: As the original data comes from the Central Bank of Costa Rica, the month abbreviations are in Spanish. Our task here is to replace these Spanish abbreviations with their English counterparts. For instance, “Ene” will be replaced with “Jan.”
  • Step 6: To maintain data consistency within Power BI, we will change the data type of the date column to “Date” format.
  • Step 7: Since the decimal point was not included in the extracted data, we need to divide each data point by 100. This can be achieved using the “divide” arithmetic operation found under the menu “Transform / Number Column / Standard.”
  • Step 8: We will rename the column headers to make them more descriptive. The date column will be named “Date,” while the exchange rate column will be titled “Currency-Buy” or “Currency-Sale,” depending on the context.
  • Step 9: We will sort the table in ascending order (Date column), add an index column, it will be useful later with our DAX code. To add an index column can be done by selecting “Add Column / General / Index Column” from the menu.
  • Step 10: Finally, to ensure a chronological order, we will sort the table in descending order, arranging the data from the most recent date to the least recent. This can be achieved by clicking on the “Date” column header and selecting “Sort Descending.”

By completing these steps, we have successfully transformed the data for the selling exchange rate. The same set of steps will be applied to the currency selling exchange rate data.

Data Loading Process

Add a Line Chart

Once the “Queries” are ready, we will close the “Power Query Editor” and return to the “Power BI Desktop.”

In the “Report Canvas” area, we will add a “Line Chart” to visualize the data. The data to be displayed is provided in the following table:

Axis Data
X-Axis
‘Buying Exchange Rate’[Date]
Y-Axis
Sum of ‘Buying Exchange Rate’[Currency-Buy]
Y-Axis
Sum of ‘Selling Exchange Rate’[Currency-Sale]

To configure the X-Axis, we right-click on it, select the “Date” box, and choose “Date” from the menu instead of “Date Hierarchy.” This improves the granularity of the data in the Line Chart.

To rename the Y-Axis Line Names, we right-click on each data box, and choose “Rename from this visual”. “Sum of Currency-Buy” will be renamed as “Buy Price”, and “Sum of Currency-Sale” as “Sale Price”.

All right, with these steps completed, we now have a valuable chart depicting the exchange rate’s behavior across all years in the dataset.

Add a couple of Cards

Next, we will create cards displaying the current values of the buying and selling exchange rates (one card for each rate). To achieve this, we will create new data fields using DAX expressions within each Query (Buying Exchange Rate / Selling Exchange Rate).

To begin, right-click on the name of one of the Queries and select “New Measure.” This will allow us to create the necessary DAX expressions for calculating the current exchange rates.

The DAX expressions are in the following table

Query Dax Expression
Buying Exchange Rate
Current Buy Price = var TheLastIndex = MAX('Buying Exchange Rate'[Index]) return CALCULATE(MAX('Buying Exchange Rate'[Currency-Buy]), 'Buying Exchange Rate'[Index] = TheLastIndex)
Selling Exchange Rate
Current Sale Price = var TheLastIndex = MAX('Selling Exchange Rate'[Index]) return CALCULATE(MAX('Selling Exchange Rate'[Currency-Sale]),'Selling Exchange Rate'[Index] = TheLastIndex)

Add a Data Table

Finally, we will insert a table containing the “Date,” “Currency-Buy,” and “Currency-Sale” data. The “Date” data will not be hierarchized, and the exchange rate data will not be summarized.

Done, the project has been completed !!!.