-
Notifications
You must be signed in to change notification settings - Fork 0
4. Extract‐Transform‐Load (ETL) in Power BI
The first step is to consolidate all the data into a single Power BI (.pbix) file. Currently, the data needs ot be extracted from four different sources (see 4.1), cleaned (see 4.2) and loaded.
The diagram below gives a quick overview of the ETL pipeline, as well as the types of transformations performed on the data.
![ETL_final](https://private-user-images.githubusercontent.com/146069012/309237128-d017d078-80ce-4249-9f50-5ac3fc1d63f0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5ODI2ODksIm5iZiI6MTcyNTk4MjM4OSwicGF0aCI6Ii8xNDYwNjkwMTIvMzA5MjM3MTI4LWQwMTdkMDc4LTgwY2UtNDI0OS05ZjUwLTVhYzNmYzFkNjNmMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMFQxNTMzMDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT01MjZkMjRkOTY2YjZmYzQ1YTkwODYwOGZiMjEwMTYzOWRmNzlkZTgwNmIxZDQ0YTY2ODUwOGM0MGVkNzM5MjdiJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.pXYiWI5B6AMGxYIQLud_ItWwsLDSRCuh-UZeOIxT0xU)
NOTE: the credentials needed to access and/or download the data are not available in this repository.
The first phase focuses on data loading and preparation. Each table was uploaded from a different source. The tables downloaded from Azure required specific credentials provided by AiCore (unavailable in this repository).
To import data into Power BI, go to Get Data
menu and find the appropriate option.
Table | Type | Imported from |
---|---|---|
Orders | Facts | Azure SQL Database |
Customers | Dimension | Combining 3 .csv files, stored in a local folder |
Products | Dimension | Local .csv file |
Stores | Dimension | Azure Blob Storage |
The figure below shows how to import data from Azure SQL Databse and Azure Blob Storage.
The figure below shows how to import data from a local .csv file or multiple files saved in a local folder.
After importing all tables to Power BI, we need to transform the data in the Power Query Editor. Common transformations to all tables include:
- Fix column naming. Throughout this process, it is important to make sure that all tables have consistent and comprehensive naming, and that their format matched the convention: for example, column names should be written as "Full Name" instead of "full_name" or "full-name".
- Ensure data types are correct and accurate.
The specific transformations performed on each table are specified in the ETL diagram above and in the sections below in more detail.
Action | Column/Condition | Reason |
---|---|---|
Delete column | Card number | Ensure data privacy |
Delete rows | If value is null | Ensure data integrity |
Split datetime column | Order date | Split into a date column and a time column |
Split datetime column | Shipping date | Split into a date column and a time column |
- To split datetime columns, go to
Split Column
>by delimiter
, and chose a blank space as the delimiter. Alternatively, duplicate the column, and choose the format as 'date' or 'time' in the data type option.
![power_query_split_col_by_delimiter](https://private-user-images.githubusercontent.com/146069012/309238565-cb04acdc-9bce-4cda-8cae-b6759b9c0951.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5ODI2ODksIm5iZiI6MTcyNTk4MjM4OSwicGF0aCI6Ii8xNDYwNjkwMTIvMzA5MjM4NTY1LWNiMDRhY2RjLTliY2UtNGNkYS04Y2FlLWI2NzU5YjljMDk1MS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMFQxNTMzMDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mZDhkMWUwNTE4NjAxMzJhNGFlMTg1ZTYzZTY3NTE1Yjg2M2Q5OWJkZWNjOWIxODhlNmFlNjY1ZDgxNzEyOWM1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.L3hO-DcU7X5fORvyeuSVFMYMbNkupNYNsQOhu0hoGLE)
- To change data type, click on the icon to the left on the column name and select the desired data type.
![power_query_change_dtype](https://private-user-images.githubusercontent.com/146069012/309238652-0dd685fd-6796-43bf-a379-c3ad6c153c17.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5ODI2ODksIm5iZiI6MTcyNTk4MjM4OSwicGF0aCI6Ii8xNDYwNjkwMTIvMzA5MjM4NjUyLTBkZDY4NWZkLTY3OTYtNDNiZi1hMzc5LWMzYWQ2YzE1M2MxNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMFQxNTMzMDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wOTA3ZTE0MzgxZTEyNjQyODViOTk1YTA1ZDQzOTc4M2Y3ZWNiZGRiODA1MGFmNjE4MTMxMTgzM2FhMzQzYzliJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.fcdwtVaDXHzNNmJgCtpRQwBCBTkCEtznpUPRVWGW4Tc)
Action | Column/Condition | Reason | Method |
---|---|---|---|
Remove duplicates | Product code | Ensure each product code is unique | See below |
Split column | weight (e.g. values: 10g) | Into weight values column and units column | Column from Examples |
Fix datatype | weight values column | To decimal | n/a |
Calculated column | New column name: Weight Kilograms | Calculated from Weight Values and Weight Units columns, to transform all values to kg | DAX (see below) |
- To remove duplicates, click on 'Remove Rows' > 'Remove Duplicates' in the Power Query Home pane:
![power_query_remove_rows_with_nulls](https://private-user-images.githubusercontent.com/146069012/309238750-35e02d3a-2d32-482e-aeda-7b57fc4a16e2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5ODI2ODksIm5iZiI6MTcyNTk4MjM4OSwicGF0aCI6Ii8xNDYwNjkwMTIvMzA5MjM4NzUwLTM1ZTAyZDNhLTJkMzItNDgyZS1hZWRhLTdiNTdmYzRhMTZlMi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMFQxNTMzMDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mZTRlNzY5MjU4MjRkODkwZDFkMzFjMzNmY2U3ZTMzOTQ0Yzg3MjQ5M2JmYWUyMTM4YTg3OTY2YTYyMmJmMGJjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.pVssLFAGSAMEsLCDHHBsZjOa5RwowanAMZ9AKNfYCfc)
- The
weight
column contains values in either in kg, g or mL. Those in mL will be approximated to g using the density of water (1 g = 1 mL). Before transforming, the data is in the format e.g. 800g, 400mL, 0.1kg. this involves multiple steps:-
- In Power Query, create 'Column from Examples' based on the weight column, containing only the numerical values.
-
![power_query_col_from_examples](https://private-user-images.githubusercontent.com/146069012/309238869-7063944d-605b-468a-983b-705e4a104b45.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5ODI2ODksIm5iZiI6MTcyNTk4MjM4OSwicGF0aCI6Ii8xNDYwNjkwMTIvMzA5MjM4ODY5LTcwNjM5NDRkLTYwNWItNDY4YS05ODNiLTcwNWU0YTEwNGI0NS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMFQxNTMzMDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT04NmZiM2IzOTRlY2FlMDVjMWUxYmUxNGQwN2U5NWE2NDhkOWEyNWY5NjhhODM1ZTNiMjA2NzNlYWZkNWRmZWM4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.MDA1TqnEM8joA8TkGT6HLjZkNAyge8U0OPS2svkAiyg)
- 2. In Power Query, create 'Column from Examples' based on the weight column, containing only the units as strings e.g. 'g'.
- 3. Load the data to Power BI (exit Power Query).
- 4. Create final weight column, containing only weights in kg (as floats): to do this go to `Data View` > `New Calculated Column`. The DAX formula used for this transformation is:
```
Weight Kilograms = IF([Weight Units]="kg", [Clean Weight Values], [Clean Weight Values]/1000)
```
The desired output should look like the column highlighted in the image below:
![weight_column](https://private-user-images.githubusercontent.com/146069012/309238953-ca19d181-bccf-4ed1-a9d1-80b21a2cf40a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5ODI2ODksIm5iZiI6MTcyNTk4MjM4OSwicGF0aCI6Ii8xNDYwNjkwMTIvMzA5MjM4OTUzLWNhMTlkMTgxLWJjY2YtNGVkMS1hOWQxLTgwYjIxYTJjZjQwYS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMFQxNTMzMDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mYWRiZDljY2E0MWJhNDk2M2RlYjE4MmE0NTk2YTA4OWI2YTEzNDAwNWMxNGNlMTVmOTk0NGQ1N2I1YWQ1ZGVlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.blzYydvrH7cOqbBripVKBC-RG-igxZMv20JbyemthR8)
The main transformation performed on this table was combining the columns First Name
and Last name
into a new column called Full name
. This can be done in Power Query by selecting both columns of interest and going to Add Column
> Merge Columns
in the Transform pane.