100% found this document useful (3 votes)
9K views

BI - Power Query Lecture Notes PDF

Power Query allows users to easily access and transform data from various sources. It consists of four tools - Power Query for data access and transformation, Power Pivot for data modeling, Power View for data visualization, and Power Map for geospatial data visualization. Power Query enables finding, connecting to, merging, shaping, cleansing, and transforming data from different sources. Queries are built in the Power Query editor by selecting data sources and defining transformation steps. Transformed data can then be loaded back to Excel as a table or range for further analysis.

Uploaded by

Phyo Aung Hein
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
9K views

BI - Power Query Lecture Notes PDF

Power Query allows users to easily access and transform data from various sources. It consists of four tools - Power Query for data access and transformation, Power Pivot for data modeling, Power View for data visualization, and Power Map for geospatial data visualization. Power Query enables finding, connecting to, merging, shaping, cleansing, and transforming data from different sources. Queries are built in the Power Query editor by selecting data sources and defining transformation steps. Transformed data can then be loaded back to Excel as a table or range for further analysis.

Uploaded by

Phyo Aung Hein
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

MEET Power Query Power BI

• What is Power BI ?
• BI stands for Business Intelligence
• Power BI is a business analytics service provided by Microsoft It provides interactive visualizations with
self-service business intelligence capabilities, where end users can create reports and dashboards by
themselves, without having to depend on information technology staff or database administrators
( Wikipedia )

Power BI consists of four powerful Tools:

Power Query: Enables customers to easily search and access public/organization's data, all within Excel

Power Pivot: For creating and customizing flexible data models within Excel

Power View: For creating interactive charts, graphs and other visual representations of data

Power Map: A 3D data visualization tool for mapping, exploring and interacting with temporal data

MEET Power Query Chapter 1: Introduction

What we can do with Power Query ?

• Find and connect data across a wide variety of sources


• Merge and shape data sources to match your data analysis
requirements or prepare it for further analysis and
modeling by tools such as Power BI, Power Pivot and
Power View
• Create custom views over data
• Perform data cleansing operations
• Import data from multiple log files
• Perform Online Search for data from a large collection of
public data sources including Wikipedia tables, a subset of
Microsoft Azure Marketplace, and a subset of Datagov
• Create a query from your Facebook likes that render an
Excel chart

1
MEET Power Query Chapter 1: Introduction

How does Power Query work ?

• Queries are defined in the Query Editor window or by using M language in Advance Editor

• Once a data source is defined, the query can be named, and steps created

• Steps can filter and shape data into a desired result

- Steps can easily be produced by applying column filters, and by using the commands available from the

ribbon, or the query and column context menus

- It is possible to select a step and preview the data at that step

- It is also possible to remove steps – but take care not to remove a step that downstream steps depend on

- Step formulas can be viewed or edited in the formula bar

- Query steps are defined by using Power Query Formula Language (informally known as "M“)

• Simple query step logic does not require writing formulas

• Advanced query step logic can be written to leverage the full power of the language

MEET Power Query Chapter 1: Introduction

How to get Power Query?


- Need External Add in to use with Excel 2010
& 2013 but in Excel 2016 & 2019, it is
included as built-in feature under Data Tab
- For Excel 2010 & 2013, Add-in can be
downloaded in this link.
http://www.microsoft.com/en-us/
download/details.aspx?id=39379

- After installing the downloaded file,


Power Query tab should be seen in the
Excel Menu Bar. If it does not appear in
the Excel Menu, the following steps have
to be done:
- Click File > Option > Add-ins >
COM Add-ins > Go
- When the add in dialog box appear, check
Power Query and then click OK

2
MEET Power Query Chapter 1: Introduction

Power Query Window

Menu Bar
(Power Query Editing Tools)

Formula Bar

Data Preview

Applied Steps

MEET Power Query Chapter 1: Introduction

Viewing Existing Queries in Excel Window

Mouse over on the table name in Workbook Queries Pane Right Click on Table Name

3
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

Supported Data Sources

Access database OData feeds


Active Directory Oracle database
CSV file SharePoint List
Excel spreadsheets SQL Server database
Facebook Text files
Folder Web pages
Hadoop Distributed File System (HDFS) Windows Azure Marketplace
IBM DB2 database Windows Azure SQL Database
MySQL database XML files

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

Contents
2.1 Importing Data ( Single Table or Range ) From Current Workbook
2.2 Loading Options
2.3 Importing Data ( Multiple Tables ) From Current Workbook
2.4 Importing Data From Other Excel Workbook ( Single sheet and not formatted as Data Table or Named Range)
2.5 Importing Data From Other Excel Workbook ( Multiple sheets and formatted as Data Tables )
2.6 Importing Data From Other Excel Workbook ( Multiple sheets and not formatted as Data Tables or Named Ranges)

2.7 Importing All Excel Files ( with Single Sheet ) from A Folder

2.8 Importing All Excel Files ( with Multiple Sheets ) from A Folder

4
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.1 Importing Data ( Single Table or Range ) From Current Workbook


Preparation
- PQ 2.1 Exercises file will be used for this lesson.
- Data Range should be Data Table to import into Power Query Editor . To convert into Data Table, click any cell
inside the Data Range, then Press Ctrl + T ( or ) Click Table under Insert Tab

Importing into Query Editor


- Click any cell inside the Data Table and under Data Tab, click “From Table” from the Get & Transform Group

In Excel 2010 & 2013, Under Power Query Tab,


click From Table/Range.

Then, Power Query Editor will be shown.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

In the power query editor, Order date is set as Date/Time format. As it is changed to Date format, we will be asked whether to
Click the upper left hand icon, and change to Date Format. replace current data or add as a new step. Click Replace.

Click filter icon on the Product column, and uncheck some items

5
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

In the right side of the query editor, we can change the query name and
see the applied procedures If the required steps are done, we can import back to
the Excel Worksheet. To do so, click the left-upper side
of query editor and click “Close and Load”.

After clicking “Close and Load”, the Query data will be loaded in a
new added sheet. When the original data change something, the
query data will be updated if we refresh the query data. ( Right
Click on the Query data table, and click Refresh )

When we add more data, the query data will be


updated ,when we click refresh, with the applied filtered data

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.2 Loading Options


- After Editing and transforming the data as required, the query data is now ready to use in Excel Worksheet, or to
interrelate with another query or to analyze in Power Pivot Data Model.
- If we choose Table, the query data will be
imported into Excel and we can decide
where to put the Table.
- By default, it is selected as “New
Worksheet”. By clicking Existing
worksheet, we can select the cell range
where to put the data.
- If we choose “Only Create Connection”,
If we click Close & Load, the query data will the data will be saved only in Power
be import back into Excel with a new Query and not loaded to Excel
worksheet. - If we check “Add this Data to the Data
If we click Close & Load to , then we will be Model”, the query data will be imported
asked where to load the data into Power Pivot Data Model

6
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.3 Importing Data ( Multiple Tables ) From Current Workbook


Preparation
- PQ 2.3 Exercises file will be used for this lesson.
- Data Range should be Data Table to import into Power Query Editor . To convert into Data Table, click any cell inside
the Data Range, then Press Ctrl + T ( or ) Click Table under Insert Tab

Importing into Query Editor We want to append only sale tables. To make it
easy, we named the table ending with _Sales.
- Go do Data Tab and click
So, we apply the filter in the Name column to get
“New Query” > “From the table ending with _Sales.
Other Sources ” > “Blank
Query”

- When we see the query


editor, write the following
formula in the formula bar

=Excel.CurrentWorkbook()

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

To extract the data from Tables, click the Expand icon As data types are not defined properly, click the data type icon and
on the Content column and click OK. change it as necessary.

It is good practice to provide the proper name to our query.

After editing as necessary, click Close & Load to


import back into Excel.

7
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.4 Importing Data From Other Workbook


(Single sheet and not formatted as Data Table or Named Range)

PQ 2.4 Exercises file is to be used for this lesson.


Importing into Query Editor
- Go do Data Tab and click “New Query” > “From File” > “From Workbook”
- When we see the Browse window, Go and Select our Excel file to import
- Then we will see the Navigator Window

Click Edit to load into Power


Query, then Query Editor window
will be opened.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

As the data range in the imported worksheet was not


formatted as Data Table, extra columns were imported
in the Query Editor.

To remove those extra columns, select the data


columns and right click , then click “Remove Other
Columns”

As we see in the picture, First row is not regarded as Column


heading. To promote the first row as Column Heading, Click “
Use First Row As Header”

Do the other necessary steps in order to get the required


format. Then, click “Close and Load” to import back into Excel
Worksheet.

8
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.5. Importing Data From Other Excel Workbook


( Multiple sheets and formatted as Data Tables )

PQ 2.5 Exercises file is to be used for this lesson.


Importing into Query Editor
- Go do Data Tab and click “New Query” > “From Other
Sources” > “Blank Query”
- When we see the Query Editor, we have to write the
following formula in the formula bar.
=Excel.Workbook(File.Contents( “Our File Location
Path” )
- Then, we will see the information column in the Query We don’t need other information column but just need Data
Editor.
column. To remove other columns, Select Data column, Right

As we want to extract the Click and click Remove Other Columns.

data only from data table,


the filter is applied on
Kind column to get only
“Table”.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

To extract the data from the Tables,


click Expand icon on the Data
Column.
Uncheck “Use original column
As we see in the above picture, all data are
name as prefix”
imported properly but the data types are not To define data type, click on Data
After editing as necessary, click “ Close Type icon and choose the proper
and Load” to import into Excel or defined properly..
data type
Powerpivot.

9
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.5. Importing Data From Other Excel Workbook


( Multiple sheets and not formatted as Data Tables or Named Ranges)
PQ 2.6 Exercises file is to be used for this lesson. This lesson is almost same with the steps done in lesson 2.5.
Importing into Query Editor
- Go do Data Tab and click “New Query” > “From Other Sources” > “Blank Query”
- When we see the Query Editor, we have to write the following formula in the formula bar.
=Excel.Workbook(File.Contents( “Our File Location Path” )
- Then, we will see the information column in the Query Editor. From those column, we just need Data column. So, Select
the data column and Right click and Remove other columns.
- Then to get the data from the Tables, click Expand icon on the Data Column.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

As we see in the picture, the first row should be the


Extra blank columns are also imported into Query. To remove those columns,
column heading. So click the leftmost icon in the column
select the data columns and right click and click “Remove Other Columns”.
heading row, then choose “Use First Row as Headers”.

To remove blank rows and column


heading of the other sheet, click filter
icon on the Customer column. When
the filter box appear, we will see the
list is not shown completely. To see
full list, click “Load more”. When we
see the full list, uncheck “null” and After editing as necessary, click
“CUSTOMER”. Then, only the required “ Close and Load” to import
data will be imported. into Excel or Powerpivot.

10
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.7 Importing All Excel Files ( with Single Sheet ) from A Folder
PQ 2.5 Exercises file is to be used for this lesson.

Importing into Query Editor


- Go do Data Tab and click “New Query” > “From File” > “From Folder”
- When we see the Browse window, Go and Select the folder which we
want to import
- Information columns for each file within the imported folder will be
seen in the Query Editor
- To ensure only excel files are imported into query editor, it is good
practice to filter the Extension Column
- To do so, click the “Filter icon” on the Extension Column, then go to
“Text Filter” and click “Ends with”

In the Filter Rows box, type “.xlsx” , then click OK.


Then, only the excel files will be seen in the Query
Editor Window.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

Now, we don’t need other information


columns but just need “Content” column. To extract the information from the
To remove the other unnecessary columns, worksheets, we have to add a
select the “Content” column and Right Click custom column.
on that. Then, select “Remove Other To do so, go to “Add Column” and
Columns” then click “Custom Column”.

When the “Add Custom Column” box appear, provide any name in the “New
column name” box. And, write the following formulas in the Custom Column
Formula box:
=ExcelWorkbook([Content])

11
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

After writing custom


formula, the new custom
column with the provided
column name will be added
in the query editor.
To extract the information,
click expand icon on the
right-handed upper side of
the custom column.

As we don’t need any other column


In the Kind column, there apart from Data column, select Data
are two types of data:
Column , Right click on it and click
DefinedName and Sheet.
“Remove other Columns.
As we need only Sheet
Data, Filter the Kind
Column to get only sheet.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

Click the Expand button on the Data Column. Then we will see all data column from every worksheet. As we see in the picture, the first row
should be the column heading. So click the leftmost icon in the column heading row, then choose “Use First Row as Headers”.

This query data has appended all data from every sheet. We
need column heading only from the first worksheet, then we
just need only data from the rest sheets. And there may be also
blanks rows in the database.
To remove blank rows and column heading of the other sheet,
click filter icon on the District Column ( you can use any column )
When the filter box appear, we will see the list is not shown
completely. To see full list, click “Load more”. When we see the
full list, uncheck “null” and “District”. Then, only the required
data will be imported.

12
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.8 Importing All Excel Files ( with Multiple Sheets ) from A Folder
PQ 2.8 Exercises file is to be used for this lesson.
Importing into Query Editor
- Go do Data Tab and click “New Query” > “From File” > “From Folder”
- When we see the Browse window, Go and Select the folder which we want to
import
- Information columns for each file within the imported folder will be seen in
the Query Editor
- Among the appeared columns, we need only Content columns and Name
columns. So, Select these two columns, Right Click and click Remove Other
Columns.
From Name column, we want to get only year and so, we need to remove
Sales.xlsx. We can do it in many ways. For now, let’s use “Split Column” features.

Click “Split When the


Column” under dialog box
Home Tab and appear, select
then choose “By “Space” as
Delimiter”. delimiter.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

To extract the data from Content column, we need to add a custom Name column will be split into two columns. We don’t need
column. To do so, click Add Custom Column under Add Column tab. Name.2 Columns and Content Column anymore. So, Select
When the custom column box appear, write the formula as those and Right Click and click Remove Columns.
=Excel.Workbook([Content])

In the new added rows


To extract the data from Table, click Expand icon on the Extracted Data and columns, we need
column. Then we will see a list of rows and columns as below: only data-existing rows
and columns.
To filter the data existing
rows, we have to apply
the filter on Kind
column to uncheck
DefinedName.

13
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

From the existing query, we need only the first three columns. To extract the data, click Expand icon on the Data
Therefore, the other columns are to be removed. column.

Extra blank columns are imported into the Query. To remove those columns,
select the Data columns, Right click and select Remove Other Columns. Apply Use First row as Header feature to promote the
first row as heading. And rename the column names to
achieve the proper query.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

We can add Index Column for the serial number. To add this, click
Index Column under Add Column and choose From 1.

The Index Column will be added to the right side of the query. To put it as the first
column, drag to the left-most and drop. And rename it as properly.

Then, we will see the proper data


set with serial number as below:

After editing as
necessary, click “
Close and Load” to
import into Excel
or Powerpivot.

14
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.9 Importing Data from Web


Data from Yangon Stock Exchange website will be imported in this lesson.

Importing into Query Editor In 2016 and above Excel version, we will be asked with this prompt box

- Go do Data Tab and click “New Query” > “From Other whether how you want to access the webpage.
Source” > “From Web”
In this exercises, we want to access the YSX website as an external visitor
- When we see the Browse window, write the website URL
so that we select “Anonymous”.
of YSX:
If we have to use User Name and Password to access this website, we may
choose other options.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.8 Importing Data from Web If we are not still sure which table to import, we can see in the Web
In the Navigator window, we can select the correct table by View where the selected table will be highlighted with green color. If
clicking Table name and se the Table preview. we want to import multiple table, check “Select multiple items” and
then we can select multiple tables.

After deciding which tables to import, select “Transform Data” to


edit in the Query. In the Query, the rest processes are same with the
above examples.

15
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.10 Importing Data From Text or CSV Files


PQ 2.10 Exercises file is to be used for this lesson.

Importing into Query Editor

Importing Text files and CSV files are almost


same. To import Text file,
- Go do Data Tab and click “New Query” >
“From File” > “From Text”

To import CSV file


- Go do Data Tab and click “New Query” >
“From File” > “From CSV”

When we see the Browse window, Go and


Select the file which we want to import

When we see the Preview window, we can


define “File Origin, Delimiter type and Data
Type Detection as necessary.
Then click Transform Data to import into
Query.

MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options

2.11 Importing Multiple Text files or CSV Files from a Folder Among from the appeared columns in Query Editor, we

PQ 2.11 Exercises file is to be used for this lesson. need Content column only.
Importing into Query Editor To remove other columns, select the Content column,
- Go do Data Tab and click “New Query” > “From File” > “From Folder” Right click and click Remove Other Columns.
- When we see the Browse window, Go and Select the folder which we
want to import
- When we see the preview window, click Transform Data to import into
Query.

Remark: Though there are only text files in the folder


currently, some other file types may be added in this
folder later. Therefore, it is good practice to apply the
filter on the Extension column to get only the “.txt”
before we remove the other columns,.

16
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
Click on Expand Icon on the Content Column, and then we will see Combine Files Dialog box.
There, we can change the File Origin, Delimiter, and Data Type Detection.

After clicking OK on the Combine


Files Dialog box, data will be
imported into query properly as
seen in the following picture.

Remark: It is good practice to apply the filter for removing null rows and
repeated header rows after importing into query.

MEET Power Query Chapter 3: Appending and Merging Queries

3.1 Appending Queries


Suppose we have imported same formatted data from different sources, and would like to combine as a single database. Then, we
can use “Appending feature” of power query.
For this exercise, Data from PQ 3.1 Exercise folder will be imported separately and choose “Only Create Connection” when we close
and load the query.
In the Append box, we can select whether we want to
Right click on one of the imported Queries, and click “Append”.
append only two tables or multiple tables more than
two tables. If we want to append only two tables, then
just select the tables to append as shown in the
following.

17
MEET Power Query Chapter 3: Appending and Merging Queries

If we want to append more than two tables, then we have to select


“Three or More Tables”. Then, select the table name and click “Add” or Then, we will see all data are imported into a new
Double click the Table name to import into the right side. Then, Click OK. Query as shown as below:

If we don’t want to create new


Query, then we can use “Append
Queries” under Home Tab.

MEET Power Query Chapter 3: Appending and Merging Queries

3.2 Merging Queries


Merging Queries require joining criteria. Joining criteria is field(s) in each source query that should be matched with each other to
build the result query.
There are 6 types of joins supported in Power BI as below, depends on the effect on the result set based on matching rows, each of
these types works differently.

18
MEET Power Query Chapter 3: Appending and Merging Queries

For this exercise, PQ 3.2 file is to be used. In this workbook, two tables are

imported into the Query: Cost and Price.

After importing into Query , Close and Load as “Only Create Connection”.

Then, Right Click on the “Cost” Query, and click “Merge”.

MEET Power Query Chapter 3: Appending and Merging Queries

i) Left Outer ( all from first, matching from second ) When the Merge Dialog box appear
- Firstly select two tables to merge
- Then, select the columns from both tables that have
matching values ( Green color highlighted )
- In the Join Kind, select “Left Outer” and then click OK
- Then we will see the Query Editor

Click Expand icon on the Price column and uncheck


other columns except Price. Then click OK.

19
MEET Power Query Chapter 3: Appending and Merging Queries

i) Left Outer ( all from first, matching from second )

Original Tables

All rows from the Left table are


included in the result table, but only
matching rows are included from
the second table.

Green Highlighted rows are not Result Table Left Outer Join
included in the result table as these
rows are not included in first table.

MEET Power Query Chapter 3: Appending and Merging Queries

ii) Right Outer ( all from second, matching from first )


Right Click on the Cost Query and Click Merge.
When the Merge Dialog box appear
- Firstly select two tables to merge
Click Expand
- Then, select the columns from both tables that have
icon on the
matching values
Price column.
- In the Join Kind, select “Right Outer” and then click OK
Then click OK.

As we import all columns from both


table, the columns were duplicated. To
remove those columns, select them,
Right click and click “Remove Columns”.

Then reorder the columns to get the


proper dataset.

20
MEET Power Query Chapter 3: Appending and Merging Queries

ii) Right Outer ( all from second, matching from first )

Original Tables

All rows from the right table are


included in the result table, but only
matching rows are included from
the first table.

Yellow Highlighted rows are not


Result Table of Right Outer Join
included in the result table as these
rows are not included in second
table.

MEET Power Query Chapter 3: Appending and Merging Queries

iii) Full Outer ( all from both )


Right Click on the Cost Query and Click Merge.
When the Merge Dialog box appear
- Firstly select two tables to merge
- Then, select the columns from both tables that have
matching values
- In the Join Kind, select “Full Outer” and then click OK

When we see the query editor, expand the Price column.

All rows from both tables are included in the result table. But it is difficult to analyze for
further analysis. Therefore, the alternative way for Full Outer will be explained later.

21
MEET Power Query Chapter 3: Appending and Merging Queries

iv) Inner ( Only Matching Rows )

Right Click on the Cost Query and Click Merge.


When the Merge Dialog box appear
- Firstly select two tables to merge
- Then, select the columns from both tables that
have matching values
- In the Join Kind, select “Inner” and then click OK

Click Expand icon on the Price column and uncheck


other columns except Price. Then click OK.

Only the rows which are included in both tables are presented in the Result table. Yellow
Highlighted rows from the first table and Green Highlighted rows from the second table
are not included in the Result table.

MEET Power Query Chapter 3: Appending and Merging Queries

v) Left Anti ( Rows only in First )

Right Click on the Cost Query and Click Merge.


When the Merge Dialog box appear
- Firstly select two tables to merge
- Then, select the columns from both tables that
have matching values
- In the Join Kind, select “Left Anti” and then click OK

Click Expand icon on the Price column and uncheck


other columns except Price. Then click OK.

Rows which are included only in First Table are presented in the
Result Table.
In the above example, only Yellow highlighted rows from the first
table are included in the Result Table.

22
MEET Power Query Chapter 3: Appending and Merging Queries

vi) Right Anti ( Rows only in Second )


Right Click on the Cost Query and Click Merge.
When the Merge Dialog box appear
- Firstly select two tables to merge
- Then, select the columns from both tables that
have matching values
- In the Join Kind, select “Right Anti” and then click
OK
Click Expand icon on the Price column. Then click OK.

Rows which are included only in Second Table are presented in the
Result Table. In the above example, only Green highlighted rows
from the second table are included in the Result Table.

As this join type take action from second column, the columns for
first table will be null. Right Click those columns and Remove.

MEET Power Query Chapter 3: Appending and Merging Queries

vii) Alternative Method for Full Outer All data from both tables are appended in the result
table as shown in the following picture.
As mentioned in the Full Outer lesson, the result from Full Outer are not
Then, we need to summarize the same items to get the
much convenient for further analysis. So, Let’s try another way .
proper dataset. To do so, we have to use “Group
Right Click on the Cost Query and Click Append.
feature”.
When the Append Dialog box appear, Select the table names to append.
Firstly select the first two columns.

23
MEET Power Query Chapter 3: Appending and Merging Queries
vii) Alternative Method for Full Outer
After selecting the first two columns, click “Group By” under Transform Tab. When the “Group By” Dialog box appear, select
“Product” and “Product Category” under the Group By.
Give the proper name under the New Column Name, and under Operation, select “Sum”. And select the Column to calculate.

Now, we have got the dataset that is merged two


tables properly and convenient for further analysis.

MEET Power Query Chapter 3: Appending and Merging Queries

Merging Queries - Exercises 1

Find the related price of each product ID in the Product table and merge them into Sale table.

Sale Table Product Table

24
MEET Power Query Chapter 3: Appending and Merging Queries
Merging Queries – Exercises 2

We have sales database for 2015 & 2016.

Find both Sales in 2015 and 2016 of the customers who

met the following criteria:

i ) Merge All Customers ( All old and new customers )

ii) All Customers who bought in 2015 ( Not including new

customers in 2016 )

iii ) Customers who bought both in 2015 & 2016

vi) Only New customers in 2016 ( who did not buy in 2015 )

v) Customers who bought in 2015 but did not buy in 2016

vi) Customers who bought in 2016 ( Not including 2015

customers who do not buy in 2016 )

MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

4.1 Transforming Data and its Types

Decimal Number – Represents a 64 bit (eight-byte) floating point

number.

Whole Number – Represents a 64 bit (eight-byte) integer value.

Date/Time – Represents both a date and time value.

Date – Represents just a Date (no time portion).

Time – Represents just Time (no Date portion).

Date/Time/Timezone – Represents a UTC Date/Time.

Duration – Represents a length of time.

Text - A Unicode character data string.

True/False – A Boolean value of either a True or False.

25
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

If we select and Right Click on the Text Data type column, If we select and Right Click on the Date Data type column,
and go to “Transform”, then we will see the options that and go to “Transform”, then we will see the options that
we can change the desired forma such as lowercase, we can change the desired format such as Year, Name of
UPPERCASE, Trim, etc. Month, Day, etc.

MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

The same transformation functions can be seen not only under Transform

Tab but also under Add Column Tab.

The difference is that,

If we use the functions under Transformation tab, the result ( transformed

data ) will be replaced the current existing data.

If we select and Right Click on the Number Data type If we use the functions under Add Column tab, the result ( transformed

column, and go to “Transform”, then we will see the data ) will be added with a new column.
options that we can change the desired forma such as
Round, Absolute, Power, etc.

26
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

4.2 Furniture Database Transformation

We have this kind of Furniture Database, but it is


difficult to analyze and/or summarize the Data.
Therefore, we want to reshape the database into a
proper tabular format as shown in the right picture.

MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 1: It is needed to format the data range as Data table or define


with a Name. In this database, it will not be okay to format as
Data table, so that the data range is to be defined with a proper
name.

Step 2: To import into Query Editor, Go to Data Tab and click From
Table/Range.

Step 3: Then the data will be imported into Query Editor. To copy down
the Category Name into the downward cells, Select the Column
1, and use Fill Down under Transform tab.

27
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 4: It is also needed to fill the year for each quarter.


But we don’t have Fill Right or Fill Left but instead
we can use just Fill Down or Fill Up.
To fill the year with Fill Down, we need to
transform the Horizontal Database to Vertical
Database. To do so, click the Transpose button
under the Transform tab.

Step 5: After the database change from to Horizontal to Vertical, use


Fill Down function to fill the year for each quarter.
Then again, we have to re-change the database from Vertical
to Horizontal.
But before doing that, we have to merge Column 1 & 2 ( Year
& Quarter together ) because Year along cannot be promoted
as Column Heading as there are duplicated years in a Row.

MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 6: Select Column 1 & 2, and click Merge Columns


under Transform tab.
When Merge Columns Dialog box appear, select
the separator ( in this example , we select Colon )
and we can also provide Name.
After two columns Merged with Colon, then click
Transpose again to transform from Horizontal to
Vertical.

Step 7: Currently, the column heading names are


given with Column1, Column2, etc. After
transposing the Database, then we can
promote the First Row as Header.
To do so, Click Use First Row as Header
under Transform tab.

28
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 8: After promoting the first row as Header, Select


the First two Columns and click Unpviot Other
Columns under Transform tab in order to
transform the database into Tabular Format.

Step 9: After Unpivoting, we will see the Tabular database as


shown in the Left Picture. But in the Attribute
column, Year and Quarter are shown together as we
have merged.
To split Year and Quarter, select that column and click
Split Column under Transform tab and then By
Delimiter.

MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 10: Then, we will be asked which separator


is to be used to split the Data. Select
the Colon as we used it when we
merged the columns.

Step 11: We have got the tabular format as we need.


Finally, change the column heading name with the proper names.

As usually, use Close and Load to for importing back into Excel or
for further data analysis.

29
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

4.3 TopUp Card Sale Database Transformation

In this Exercise, it is to transform the above TopUp


Sales database to be Tabular Format as shown in the
Right Picture so that the database is convenient for
Data Analysis.

MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 1: To import into Query Editor, firstly Define the Data Range
with a proper Name. And Click From Table/Range under Data
Tab. Then, Data range will be imported into Query Editor.
As shown in the Editor, it is needed to fill the Month Name for
each TopUp Card. To do so, firstly the data range should be
converted from Horizontal into Vertical. Therefore, click
Transpose under Transform tab.

Step 2: After the data range is converted into


vertical, the month names should be filled
down for Each TopUp Card.
To do so, select the Column 1 and click Fill >
Down under Transform tab.

30
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 3: After filling down the month names, the data range have to
be converted again from Vertical to Horizontal. Before
converting the Data Range, Column 1 & 2 should be Merged
so that it can be promoted as Heading.
For this reason, select the first two columns and Right Click
on those two columns. Then, Click Merge Columns.

Step 4: When the Merge columns dialog appear,


select the Colon as Separator.
After clicking OK, two columns will be
merged into one column.

MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 4: Then click Transpose under Transform tab


to convert from Horizontal into Vertical.

Step 5: After Transposing the Data Range, Click Use


First Row as Headers under Transform tab to
promote the first row as Column Heading.

31
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 6: To change Pivot Format into Tabular Format, we have to


Unpivot the Data Column.
To Unpivot the Data columns, Select the First two columns and
Right click on those columns and click Unpivot Other Columns.

Step 7: After Unpivoting the Data columns, the data


range looks fine. But, Attribute column includes
Month and TopUp cards together. Therefore, it is
needed to use Split Column and click By
Delimiter to separate Month and Card Types..

MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies

Step 8: After Splitting the Column, Rename the column heading with a proper name.
Then the data range is ready for further data analysis.

32

You might also like