BI - Power Query Lecture Notes PDF
BI - Power Query Lecture Notes PDF
• 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 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
1
MEET Power Query Chapter 1: Introduction
• 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 easily be produced by applying column filters, and by using the commands available from the
- It is also possible to remove steps – but take care not to remove a step that downstream steps depend on
- Query steps are defined by using Power Query Formula Language (informally known as "M“)
• Advanced query step logic can be written to leverage the full power of the language
2
MEET Power Query Chapter 1: Introduction
Menu Bar
(Power Query Editing Tools)
Formula Bar
Data Preview
Applied Steps
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
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
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 )
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
6
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
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”
=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.
7
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
8
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
9
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
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.
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
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
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.
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])
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.
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
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.
15
MEET Power Query Chapter 2: Importing Data from Multiple Sources and Loading Options
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.
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.
Remark: It is good practice to apply the filter for removing null rows and
repeated header rows after importing into query.
17
MEET Power Query Chapter 3: Appending and Merging Queries
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
After importing into Query , Close and Load as “Only Create Connection”.
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
19
MEET Power Query Chapter 3: Appending and Merging Queries
Original Tables
Green Highlighted rows are not Result Table Left Outer Join
included in the result table as these
rows are not included in first table.
20
MEET Power Query Chapter 3: Appending and Merging Queries
Original Tables
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
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.
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
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.
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.
Find the related price of each product ID in the Product table and merge them into Sale table.
24
MEET Power Query Chapter 3: Appending and Merging Queries
Merging Queries – Exercises 2
customers in 2016 )
vi) Only New customers in 2016 ( who did not buy in 2015 )
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies
number.
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
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
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies
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
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies
28
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies
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
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.
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.
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies
31
MEET Power Query Chapter 4: Handling Data Types and Data Transformation Case Studies
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