Professional Documents
Culture Documents
PowerBI G2-v3
PowerBI G2-v3
Co-op Project
Group 2
Members:
Chuyi Zhang (Group Lead)
Annie Song
Felix Chen
Project Overview
This project is designed to perform the upgrade of some major
technologies used to support the course for Jay Liu at Victoria
Training Center, and this document describes the detailed work items
required for this technology upgrade.
This requirement document is to request working on the following
technology enhancement or migration, to modernize, optimize, and
consolidate the existing version of the course, Microsoft Power BI
(Power BI). With the project completion, the enhanced features
running on the upgraded system design will offer a better designed,
documented, improved, and standardized environment, which
supports a new look of the technologies the course runs on, and offer
a nicely-looking infrastructure of the new version of the course.
2
Task Distribution
No. Contents Performer
Virtual Machine (C1, C4B)
2.1 & 2.2 Skip
Using VM as a Server (C1 – C7)
Enlarging Dataset to 20 Million and Up-to-Date (C1
2.3 & 2.4 – C3) Chuyi Zhang
Dynamic Increase of Up-to-Date Data (C3 – C5)
2.5 More Data Sources (C1 – C4A) (Optional) Chuyi Zhang
Python in Power BI (New, maybe C5, C6)
2.6 & 2.7 Felix Chen
R in Power BI (New, maybe C5, C6)
Adding More KPI with Charts in Reports (C4, C5) Annie Song,
2.8 & 2.9
Adding More Geometrical Reports (C4, C5) Chuyi Zhang
Report Deployment (C4, C5)
2.10 & 2.11
Version Consolidation (C1 – C7)
3
2.1 -2.2 Virtual Machine (C1, C4B)
& Using VM as a Server (C1 – C7)
Target
Use only one Virtual Machine for the whole process
4
2.3 Enlarging Dataset to 20 Million and Up-to-
Date
(by Chuyi Zhang)
Target
Using the VM as a server/servicing
up to 20 million
Let data up-to-date to build reports in Power BI
5
2.3 Enlarging Dataset to 20 Million and Up-to-
Date
(by Chuyi Zhang)
Work on table [Orders]
• Create table [Receivers] with columns [ShipName], [ShipAddress],
[ShipCity], [ShipRegion], [ShipPostalCode], [ShipCountry],
[CreditCard] from table [Orders], and its own identity numeric
column [ReceiverID].
• Create table [CustomerRownum] with column [CustomerID] from
table [Customers] and its own identity numeric column
[CustomerRN]
12
2.4 Dynamic Increase of Up-to-Date Data
(by Chuyi Zhang)
• Fill ’New Linked
Server’ dialog as
showed
- Linked Server:
- Provider:
- Product name
- Data source
- Provider string
• Click OK
13
2.4 Dynamic Increase of Up-to-Date Data
(by Chuyi Zhang)
• In created linked server
‘EXCELDATA’, the Excel data
source file’ Sheet(s) show
under ‘Tables’
• Create the linked server by
execute stored procedure
• Be sure the configuration of the
‘SQL Server Properties’ – ‘Log
On’ is ‘Local System’
16
2.4 Dynamic Increase of Up-to-Date Data
(by Chuyi Zhang)
17
2.4 Dynamic Increase of Up-to-Date Data
(by Chuyi Zhang)
• Add new step(s)
- Create a Step name
as ‘UptoDate’
- Type: T-SQL
- Database: Orders
- Command:
Execute
usp_Uptodate_Orders_
Details
18
2.4 Dynamic Increase of Up-to-Date Data
(by Chuyi Zhang)
Add new
Schedules
19
2.4 Dynamic Increase of Up-to-Date Data
(by Chuyi Zhang)
Add new schedules
- Name
- Schedule type
- Frequency
- Duration
- Summary
20
2.4 Dynamic Increase of Up-to-Date Data
(by Chuyi Zhang)
(Optional) Check and show new upgraded data (current
date), specific date’s data
• check and show current date upgrade data:
[dbo.usp_UpgradeShow]
• check and show special date ('yyyy-mm-dd') upgrade data
[dbo.usp_CheckShow]
Target:
22
2.5. (Optional) More Data Sources (C1 –
C4A) (by Chuyi Zhang)
• In SSMS, create view [vw_USProductionSourceOrder].
There are 2-letter code as abbreviations for U.S. states
name in [Region] column.
• In Power BI, Import Mode, import view
[vw_USProductionSourceOrder]
• Get data in ‘Web’ data source, enter the link
https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviati
ons
Check code in file: Power BI 2.5(optional)-Chuyi Z.docx
Check details in file: PowerBI 2.5(optional) -Chuyi Z.sql
PowerBI 2.5(optional)-Chuyi Zhang.pbix 23
2.5. (Optional) More Data Sources (C1 –
C4A) (by Chuyi Zhang)
• choose tabel ‘Codes and abbreviations for US states,
federal district, territories, and other’ to load
24
2.5. (Optional) More Data Sources (C1 –
C4A) (by Chuyi Zhang)
• Rename columns that you need to
• On column ‘USPS’, set Data category to ‘State or
Province’
25
2.5. (Optional) More Data Sources (C1 –
C4A) (by Chuyi Zhang)
• Go to ‘Relationships’, create relationship between
columns [ProductRegion] and [USPS]
26
2.5. (Optional) More Data Sources (C1 –
C4A) (by Chuyi Zhang)
Create ‘Matrix’ and ‘Map’
27
2.6 Python in Power BI (New, maybe C5, C6)
28
Install python and package
• To run Python scripts in Power BI Desktop, you need to install Python on
your local machine. You can download Python from the Python website.
The Power BI Python integration requires the installation of two Python
packages: pandas, matplotlib.
29
Extract data from SQL server
• To prep the data from SQL server, here I exported the orders table from the
orders database as txt file with 2,241,124 rows called Orders_orders.txt
30
Import data in Power BI
using Python
31
32
Visualize data in
Power BI using
Python
• Our goal here is to plot a chart
showing the number of orders by
year.
• Select Python visual from the pane
and drag Year, OrderID into Values,
then change OrderID to count.
33
• A script editor will pop up automatically, then key in the codes below, and click the run
button.
import matplotlib.pyplot as plt
plt.plot(dataset.Year,dataset.OrderID)
plt.xlabel('Year')
plt.ylabel('Count of Orders')
plt.title('Count of Orders by Year')
plt.show() 34
• Right figure shows the
number of orders by
year chart.
35
2.7. R in Power BI (New, maybe C5, C6)
• Install R and package
• Extract data from SQL server
• Import data in Power BI using R
• Visualize data in Power BI using R
36
Install R and package
• To run R scripts in Power BI Desktop, you need to install R on your local
machine. The Power BI R integration requires the installation of R package:
ggplot2
37
Extract data from SQL server
• To prep the data from SQL server, here I exported the orders table from the
orders database as txt file with 2,241,124 rows called Orders_orders.txt
38
Import data in
Power BI using R
• Import the txt file in Power
BI using Get Data, choose R
Script and input:
• Data <-
read.csv("C:\\Orders_Order
s.txt", sep=",")
39
40
Visualize data in
Power BI using R
• Our goal here is to plot a chart
showing the number of orders by
year.
• Select R visual from the pane and
drag Year, OrderID into Values, then
change OrderID to count.
41
• A script editor will pop up automatically, then key in
the codes below, and click the run button.
library(ggplot2)
ggplot(data=dataset, aes(x=Year, y=OrderID)) +
geom_line() +
ggtitle("Count of Orders by Year") +
labs(x="Year", y="Count of Orders")
42
Below figure shows the number of orders by year
chart.
43
2.8: Adding More KPI with Charts in Reports
Task requirements:
Add three more reports to show KPI with proper visualization by
using both DAX-based and database-based solutions.
as below:
44
2.8.1: Employee Average Sales Amount
The average value of current year 2019 is compared with last year
2018, in the sense of percentage change to evaluate the
performance of employee average sales amount is calculated by
(Ave_2019 – Ave_2018) / Ave_2018.
45
2.8.1: Employee Average Sales Amount
Steps:
Go SSMS, execute T-SQL scripts to generate an aggregated table, then
loads the table into PBI for creating the KPI.
Script:
Create a view “vw_KPI_Employee_Average_Sales”.
46
2.8.1: Employee Average Sales Amount
Go Power BI Desktop (PBI), click “Get data”, select SQL Server database,
type “VM-DA-BI\POWERBI” as server name, and “Orders” as database
Name, check “Import” as data connectivity mode, “OK”.
Go“Navigator”, check “vw_KPI_Employee_Average_Sales”, then click
“Load”, the table is loaded in PBI.
Go “Modeling” tab at ribbon, click on “New Column”, type in “Target =
0.3”, which means that increase in employee average sales amount.
Go report canvas at right side, select “KPI” in “Visualization” tab.
Set the parameter values.
47
2.8.1: Employee Average Sales Amount
Now use Dax:
Go PBI, get data from SQL Server database, which selected [Orders] and
[Order Details] to load.
48
2.8.1: Employee Average Sales Amount
Build two measures for employee average sales amount for current year
2019 and last year 2018.
49
2.8.1: Employee Average Sales Amount
Create two more measures, the current year number and current year
percentage change on employee average sales amount, these will be used
to build KPI.
The results:
Two KPI, created by DAX and by T-SQL, are same.
50
2.8.2: Customer Average Shopping
Spending
Create formula first, compute the customer average spending
amount and the average value of current year 2019 is
compared with 2018, the performance on customer average
spending amount is calculated by (Ave_2019 – Ave_2018) /
Ave_2018.
Calculate year of 2019 first, then year of 2018, load two tables
to PBI.
51
2.8.2: Customer Average Shopping Spending
T-SQL script:
52
2.8.2: Customer Average Shopping
Spending
53
2.8.2: Customer Average Shopping Spending
Use DAX, load two tables [Orders] and [Order Details] to
PBI.
54
2.8.2: Customer Average Shopping
Spending
Create two more measures, the current year of 2019 number and
current year percentage change on customer average purchase
amount.
55
2.8.3: Shipping Company Average Delivery Duration
Use AVG() function to calculate the average of dates for current year 2019
and last year 2018.
Purpose: The company tries to shorten delivery duration that the average
delivery duration.
56
2.8.3: Shipping Company Average Delivery Duration
57
2.8.3: Shipping Company Average Delivery Duration
Go PBI, use DAX, load [Orders] and [Order Details] tables from SQL
server, select [Orders] table to create a new column called “Duration”.
58
2.9: Adding More Geometrical Reports
Task requirements:
59
2.9.1: Employee-location based sales
60
2.9.1: Employee-location based sales
Go PBI, load the view to PBI Desktop:
61
2.9.1: Employee-location based sales
Go report canvas, drag “ShipCountry” to the blank area and drop it
at the field we designed to, creates a map with “bubbles”.
62
2.9.1: Employee-location based sales
63
2.9.1: Employee-location based sales
64
2.9.1: Employee-location based sales
Now use DAX, load [Orders] and [Order Details] from SQL
Server to PBI, add two measures by using DAXs.
66
2.9.2: Customer-location based spending
Create the report is as follows:
67
2.9.2: Customer-location based spending
Use DAX, load [Orders] and [Order Details] from SQL Server to
PBI, create two measures as follows:
68
2.9.2: Customer-location based spending
The report is exactly the same by using two methods SQL and
DAX.
69
2.9.3: Product-location based ordered
Calculate the average number of product per order of grouped by
countries for year 2019. Use two methods.
70
2.9.3: Product-location based ordered
Report generated by T-SQL below is same like using DAX.
71
2.8. Adding More KPI with Charts in Reports
(Complement) by Chuyi Zhang
DAX-based solutions:
In SSMS, create view [vm_KPIsource01] as
data source, to reduce the data size that need to
import into Power BI and to avoid touching up-to-
date data source directly
Use Import Mode in Power BI, import view
[vm_KPIsource01] as data source
Create reports in Power BI
Sort ascending
by ‘Sales Year’
74
2.8.1: Employee Average Sales Amount (Import Mode)
(Complement) by Chuyi Zhang
Sort ascending
by ‘Sales Year’
75
2.8.1: Employee Average Sales Amount (Import Mode)
(Complement) by Chuyi Zhang
76
2.8.1: Employee Average Sales Amount (DirectQuery Mode)
(Complement) by Chuyi Zhang
77
2.8.2: Customer Average Shopping Spending (Import Mode)
(Complement) by Chuyi Zhang
Create Table [KPI_Customer Average Spending] using DAX query.
Use Summarizecolumns function, list Year, Customer amount per
year, and total Sales per year.
Sort ascending
by ‘Sales Year’
78
2.8.2: Customer Average Shopping Spending (Import Mode)
(Complement) by Chuyi Zhang
Add column ‘Customer Average Spending’ by ‘Yearly Sales’ / ‘Customers
Amount’
Sort ascending
by ‘Sales Year’
79
2.8.2: Customer Average Shopping Spending (Import Mode)
(Complement) by Chuyi Zhang
Create ‘column chart’ and ‘table’ from [KPI_Customers Average Spending]
80
2.8.2: Customer Average Shopping Spending
(DirectQuery Mode)
(Complement) by Chuyi Zhang
Create ‘column chart’ and ‘table’ from view
[vw_KPIcustomerAveShopping]
81
2.8.3: Shipping Company Average Delivery Duration
(Import Mode)
(Complement) by Chuyi Zhang
Create Table [KPI_Shipping Average Delivary] using DAX query.
Use Groupby function, list Year, average ShipDuration
Sort ascending
by ‘Year’
82
2.8.3: Shipping Company Average Delivery Duration
(Import Mode)
(Complement) by Chuyi Zhang
Create ‘column chart’ and ‘table’ from [KPI_Shipping Average Delivary]
83
2.8.3: Shipping Company Average Delivery Duration
(DirectQuery Mode)
(Complement) by Chuyi Zhang
Create ‘column chart’ and ‘table’ from view
[vw_KPIcompanyAveDelivery
84
2.9. Adding More Geometrical Reports
(Complement) by Chuyi Zhang
DAX-based solutions:
In SSMS, create views [vm_KPIsource01] and
[vw_ProductionLocationSourceOrder] as data
source, to reduce the data size that need to import
into Power BI and to avoid touching up-to-date data
source directly
Use Import Mode in Power BI, import views
[vm_KPIsource01] and
[vw_ProductionLocationSourceOrder] as data source
Check code in file: Power BI 2.8-2.9 v3 - Chuyi Z.docx
Check details in file: Sql PowerBI 2.8-2.9 v3.sql
PowerBI 2.8-2.9 DAX-Chuyi Zhang.pbix
PowerBI 2.8-2.9 DirectQuery-Chuyi Zhang.pbix
85
2.9. Adding More Geometrical Reports
(Complement) by Chuyi Zhang
Create reports in Power BI
Database-based solutions:
In SSMS, create views as data source, to
reduce the data size that need to run in Power BI
and to avoid touching up-to-date data source
directly
Use DirectQuery Mode in Power BI
Create reports in Power BI
Check code in file: Power BI 2.8-2.9 v3 - Chuyi Z.docx
Check details in file: Sql PowerBI 2.8-2.9 v3.sql
PowerBI 2.8-2.9 DAX-Chuyi Zhang.pbix
PowerBI 2.8-2.9 DirectQuery-Chuyi Zhang.pbix
86
2.9.1. Employee-location based sales (Import Mode)
(Complement) by Chuyi Zhang
87
2.9.1. Employee-location based sales (DirectQuery Mode)
(Complement) by Chuyi Zhang
Create ‘Matrix’ and ‘Map’ from views [vw_EmployeeLocationSales]
88
2.9.2. Customer-location based spending (Import Mode)
(Complement) by Chuyi Zhang
89
2.9.2. Customer-location based spending (DirectQuery Mode)
(Complement) by Chuyi Zhang
90
2.9.3. Product-location based ordered (Import Mode)
(Complement) by Chuyi Zhang
91
2.9.3. Product-location based ordered (DirectQuery Mode)
(Complement) by Chuyi Zhang
92
2.10 Report Deployment (C4, C5)
(by Chuyi Zhang)
Target:
Deploy reports developed in 2.8 and 2.9 on cloud (Power
Service on powerbi.microsoft.com)
93
2.10 Report Deployment (C4, C5)
(by Chuyi Zhang)
Deploy reports on premises
In ‘DirectQuery’ Mode, File -> Options and Settings -> Options ->
Preview features -> Select ‘Automatice Page Refresh’
94
2.10 Report Deployment (C4, C5)
(by Chuyi Zhang)
Deploy reports on premises
At the report page that need to enable refresh,
‘Visualizations’ pane -> ‘Formatting’ -> ‘Page
refresh’ (near the bottom of the pane)
- Set Duration
95
2.10 Report Deployment (C4, C5)
(by Chuyi Zhang)
Deploy reports on cloud
• In ‘DirectQuery’ Mode,
Home -> Pulish
• Sign in
• Repeat the same steps
as in Power BI Desktop
‘Visualizations’ pane
96
2.11 Version Consolidation (C1 –
C7)
Target: (by Chuyi Zhang)
Catch up the newest version of Power BI Desktop across
the entire project
Steps:
Download the newest version of Power BI Desktop
Reinstall Power BI Desktop
Open it, check options and settings, such as refresh
settings, to match what you need
Update other software applications if need, such as SSMS
97