SlideShare a Scribd company logo
Analytics with Power BI & R
- Hands on Session
Naresh Jasotani
Email: njasotani@miraclesoft.com
Director - Data & Analytics Services
Miracle Software Systems Inc.
October 2017
2 | P a g e
Table of Contents
1. Introduction .........................................................................................................................................3
2. Prerequisite..........................................................................................................................................3
3. Hands On #1.........................................................................................................................................3
3.1. Download the data .....................................................................................................................3
3.2. Open Power BI............................................................................................................................3
3.3. Import the data in Power BI.........................................................................................................3
3.4. Visualize the data........................................................................................................................5
3.5. Understand the data and trends ..................................................................................................7
4. Hands On #2.........................................................................................................................................7
4.1. Creating a R visual.......................................................................................................................7
4.2. Creating a Boxplot using R visual................................................................................................10
4.3. Create a ggplot using R visual.....................................................................................................11
5. Hands on #3 .......................................................................................................................................12
5.1. Time series forecasting using ARIMA alogrithm ...........................................................................12
5.2. Time series forecasting using custom visual ................................................................................13
5.3. Creating a predicted data table from R – ARIMA algorithm ..........................................................14
3 | P a g e
1. Introduction
Analytics with Power BI and R - A Hands on session
Organizations are looking to transform their data processing efforts into analytics and reports,
which gives them real-time insights into their business using machine learning and R recently.
Microsoft power BI as a self-service BI tool, which defines an approach for enabling self-service
analytics helps people to easily extract data from different sources, apply data transformation
for visualizing data in an appropriate way. R become a language for data analysis and machine
learning.
Recently, Microsoft enabled users to use R codes and visuals inside the Power BI. These hands
on exercises are designed to get you started with R codes, and visuals in Power BI.
2. Prerequisite
 Please bring your own laptops, with at least 4 GB of RAM. Laptop should be enabled to connect
to Wi-Fi or internet using mobile hot-spot.
 Please download and install the Power BI Desktop software from the location below:
https://powerbi.microsoft.com/en-us/desktop/
3. Hands On #1
3.1. Download the data
 Download the csv data from the following location, save it on your C: drive.
https://drive.google.com/open?id=0B-RQ0-9g-k1lWVdrVzBYN3BQQms
 Create a folder C:R
 The csv file should be available at this location – C:RRetail_Sales_Data.csv
3.2. Open Power BI
From the Desktop (or from the start menu) click on the following icon to launch the Power
BI Desktop
3.3. Import the data in Power BI
 Close the Sign-in window page if prompted, after opening the Power BI.
 Click on Get Data option on the under the Home Menu, and then select More.
4 | P a g e
 Click on Text/CSV, Click on Connect. Navigate to C:RRetail_Sales_Data.csv.
5 | P a g e
 Click on Load
3.4. Visualize the data
 On the right hand side Fields Menu, you would see a list of columns, as shown in the
screenshot below.
 Click on the checkbox next to SalesDate, Sales_Amt columns.
 Click on the small arrow next to SalesDate in the Visualizations section. Select the
SalesDate instead of Date Hierarchy.
 Click on the Line Chart from the Visualizations section (1st
icon on the 2nd
Row)
 Click anywhere on the page (white space outside the line chart, so that the line chart
is not selected).
 Select the checkbox next to ItemName under the Fields section.
6 | P a g e
 You would see a list of Item Names appearing on Page. Move the ItemName section on
the right side.
 Adjust the Line Chart to look something like this. Select the ItemName list section on the
right, and then select the Slicer (Filter Icon on the last row, 1st
Icon) from the
Visualization Section.
 Change the text size of the ItemName Slicer to 12 from the the Visualization Section
Navigation shown below.
7 | P a g e
3.5. Understand the data and trends
 Select Think Pad 450s from the Slicer, and see the trend against time.
 Select the Line Chart, and then select the Sales_Cost from the Fields.
 From the top ribbon, under Home Menu, select Text Box, and add the heading - Daily
Sales Trend.
4. Hands On #2
4.1. Creating a R visual
 Create a new page by clicking on the + icon for the new page, at the bottom left side of
the window. A new Page-2 is created.
 Add a Slicer for ItemNames similar to the slicer in Page-1 (steps included in the above
Hands on #1 section)
 In the Visualization section, in the last row of the available charts, find the R script
visual.
 Click on the R script visual, then click on the Enable button, as shown below.
Please note that if you don’t have R installed on your system, then download and install
R from the following location:
https://mran.revolutionanalytics.com/open/
8 | P a g e
 The R visual will look something like this. Select Sales_Amt, Sales_Cost and Sales_Qty
from the Fields section.
9 | P a g e
 In the R script section of the visual, copy-paste the following code, and then click
Run Script. Please note that you have to install.packges(‘ggplot2’), if you haven’t
used ggplot2 package before.
library(ggplot2)
t<-plot(dataset)
 Select Think Pad 450s from the slicer option. The plot would look like this:
Congratulations!! You have successfully ran R script from Power BI.
10 | P a g e
4.2. Creating a Boxplot using R visual
 Select another R visual on the same page, and then select ItemName, Sales_Qty and
Discount.
 Then write the following piece of code, in the R script area; then click on Run Script.
boxplot(dataset$Sales_Qty, main="Boxplot", ylab="Sales_Qty")
 Select Think Pad 450s from the slicer option. The plot would look like this:
 To find a correlation between Sales_Qty and Discount, use # symbol to comment out
the first line of code, then add the following piece of code, in the R script area; click on
Run Script. Observe that the correlation between Discount and Sales_Qty
#boxplot(dataset$Sales_Qty, main="Boxplot", ylab="Sales_Qty")
boxplot(Discount~Sales_Qty,data=dataset, main="Boxplot", ylab="Sales_Qty")
11 | P a g e
4.3. Create a ggplot using R visual
 Install the ggplot2 package using the R console.
install.packages(‘ggplot2’)
 Go back to Power BI, then create a new page by clicking on the + icon for the new page,
at the bottom left side of the window. A new Page-3 is created.
 In the Visualization section, in the last row of the available charts, find the R script
visual.
 Click on the R script visual, then click on the Enable button, as shown below.
 Select another R visual on the same page, and then select ItemName, Sales_Qty and
Discount.
 Then write the following piece of code, in the R script area; then click on Run Script.
library(ggplot2)
ggplot(dataset, aes(x = ItemName , y = Sales_Qty,fill = ItemName )) + geom_bar(width
= 0.85, stat="identity")
12 | P a g e
5. Hands on #3
5.1. Time series forecasting using ARIMA alogrithm
 Create a new page by clicking on the + icon for the new page, at the bottom left side of
the window. A new Page-4 is created.
 Add a Slicer for ItemNames similar to the slicer in Page-1 (steps included in the above
Hands on #1 section)
 In the Visualization section, in the last row of the available charts, find the R script
visual.
 Click on the R script visual, then click on the Enable button, as shown below.
 Select another R visual on the same page, and then select SalesDate, Sales_Amt.
 Then write the following piece of code, in the R script area; then click on Run Script.
Please install forecast and tseries R-packages if not already installed.
library(forecast)
library(tseries)
ARIMA_Sales<-ts(dataset$Sales_Amt,start=c(1))
Sales_Forecast<-auto.arima(ARIMA_Sales, seasonal=TRUE)
Predicted_Sales<- forecast(Sales_Forecast, h=10)
plot(Predicted_Sales)
13 | P a g e
5.2. Time series forecasting using custom visual
 Create a new page by clicking on the + icon for the new page, at the bottom left side of
the window. A new Page-5 is created.
 Add a Slicer for ItemNames similar to the slicer in Page-1 (steps included in the above
Hands on #1 section)
 From the Visualization section, click on the (…), and then select Import from store
option. Please note that you need a Power BI account. You can sign-up for a free account
using your corporate email id on powerbi.com
 From the Advanced Analytics section, click on Add button against Forecasting with
ARIMA.
 You will see an additional visual appearing in the Visualizations section.
 Click on the Forecasting with ARIMA visual, and then drag and drop the SalesDate in the
Date section of the visual, and the Sales_Amt in the values section.
Please be patient, it may take a few minutes to load.
14 | P a g e
5.3. Creating a predicted data table from R – ARIMA algorithm
 Click on Edit Queries from the Home menu on the top of the window. A new window
opens up like this.
 In the Query Editor, click on the New Source -> More from the top of the window, and
then click on the R Script.
 Enter the following code in the R editor window. Please install forecast and tseries R-
packages if not already installed.
dataset <- read.csv('C:RRetail_Sales_Data.csv', header=TRUE,
stringsAsFactors=FALSE)
library(forecast)
library(tseries)
ARIMA_Sales<-ts(dataset$Sales_Amt,start=c(1))
Sales_Forecast<-auto.arima(ARIMA_Sales, seasonal=TRUE)
Predicted_Sales<- forecast(Sales_Forecast, h=10)
plot(Predicted_Sales)
Predicted_Sales_Table <- data.frame(Predicted_Sales)
15 | P a g e
 In the Navigator window, you would see an option to select the data or the output
Predicted_Sales_Table. Select the second one.
16 | P a g e
 You would see the predicted output table is added to the data model.
Congratulations!! You have successfully learnt various methods of executing R
scripts from Power BI.

More Related Content

Similar to Analytics with Power BI and R

Informatica complex transformation ii
Informatica complex transformation iiInformatica complex transformation ii
Informatica complex transformation iiAmit Sharma
 
Datastream professional getting started guide
Datastream professional   getting started guideDatastream professional   getting started guide
Datastream professional getting started guide
Ita Kamis
 
Administration Guide for Risk Insight 1.1
Administration Guide for Risk Insight 1.1Administration Guide for Risk Insight 1.1
Administration Guide for Risk Insight 1.1
Protect724gopi
 
Hyerion Public Sector Planning-Issam Hejazin
Hyerion Public Sector Planning-Issam HejazinHyerion Public Sector Planning-Issam Hejazin
Hyerion Public Sector Planning-Issam HejazinIssam Hejazin
 
Developing ssrs-reports-for-dynamics-ax
Developing ssrs-reports-for-dynamics-axDeveloping ssrs-reports-for-dynamics-ax
Developing ssrs-reports-for-dynamics-axNicc Ngo
 
Events Registration System Part 1
Events Registration System Part 1Events Registration System Part 1
Events Registration System Part 1
Adolfo Nasol
 
R Visualizations in SAP Analytics Cloud
R Visualizations in SAP Analytics CloudR Visualizations in SAP Analytics Cloud
R Visualizations in SAP Analytics Cloud
Geetha Madhuri
 
© SAP SE CASE STUDY .docx
 © SAP SE   CASE STUDY .docx © SAP SE   CASE STUDY .docx
© SAP SE CASE STUDY .docx
mayank272369
 
Data visualisation with sap lumira
Data visualisation with sap lumiraData visualisation with sap lumira
Data visualisation with sap lumira
Supratim Ray
 
Sales force certification-lab-ii
Sales force certification-lab-iiSales force certification-lab-ii
Sales force certification-lab-iiAmit Sharma
 
SAC_Planning.pdf
SAC_Planning.pdfSAC_Planning.pdf
SAC_Planning.pdf
Roth-williams Adjibi
 
Report exchange designer
Report exchange designerReport exchange designer
Report exchange designerrlsotto
 
Analysis by Dimensions online training
Analysis by Dimensions online training   Analysis by Dimensions online training
Analysis by Dimensions online training
Scroll Up
 
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01Ahmed Farag
 
MaxTECH Technical Training Presentation from MaximoWorld 2018
MaxTECH Technical Training Presentation from MaximoWorld 2018MaxTECH Technical Training Presentation from MaximoWorld 2018
MaxTECH Technical Training Presentation from MaximoWorld 2018
Helen Fisher
 
Birt (business intelligence and reporting tools)
Birt (business intelligence and reporting tools)Birt (business intelligence and reporting tools)
Birt (business intelligence and reporting tools)
Dharmesh Kumar Sharma
 
Creating modeled views
Creating modeled viewsCreating modeled views
Creating modeled views
Emerson Carlos Rocha
 
Remedy Presentation
Remedy PresentationRemedy Presentation
Remedy Presentation
Charrisa Coulibaly
 
An introduction to hyperion public sector planning
An introduction to hyperion public sector planningAn introduction to hyperion public sector planning
An introduction to hyperion public sector planningAmit Sharma
 

Similar to Analytics with Power BI and R (20)

Informatica complex transformation ii
Informatica complex transformation iiInformatica complex transformation ii
Informatica complex transformation ii
 
Datastream professional getting started guide
Datastream professional   getting started guideDatastream professional   getting started guide
Datastream professional getting started guide
 
Administration Guide for Risk Insight 1.1
Administration Guide for Risk Insight 1.1Administration Guide for Risk Insight 1.1
Administration Guide for Risk Insight 1.1
 
Hyerion Public Sector Planning-Issam Hejazin
Hyerion Public Sector Planning-Issam HejazinHyerion Public Sector Planning-Issam Hejazin
Hyerion Public Sector Planning-Issam Hejazin
 
Developing ssrs-reports-for-dynamics-ax
Developing ssrs-reports-for-dynamics-axDeveloping ssrs-reports-for-dynamics-ax
Developing ssrs-reports-for-dynamics-ax
 
Events Registration System Part 1
Events Registration System Part 1Events Registration System Part 1
Events Registration System Part 1
 
R Visualizations in SAP Analytics Cloud
R Visualizations in SAP Analytics CloudR Visualizations in SAP Analytics Cloud
R Visualizations in SAP Analytics Cloud
 
Exp31sp1 at a-glance-en
Exp31sp1 at a-glance-enExp31sp1 at a-glance-en
Exp31sp1 at a-glance-en
 
© SAP SE CASE STUDY .docx
 © SAP SE   CASE STUDY .docx © SAP SE   CASE STUDY .docx
© SAP SE CASE STUDY .docx
 
Data visualisation with sap lumira
Data visualisation with sap lumiraData visualisation with sap lumira
Data visualisation with sap lumira
 
Sales force certification-lab-ii
Sales force certification-lab-iiSales force certification-lab-ii
Sales force certification-lab-ii
 
SAC_Planning.pdf
SAC_Planning.pdfSAC_Planning.pdf
SAC_Planning.pdf
 
Report exchange designer
Report exchange designerReport exchange designer
Report exchange designer
 
Analysis by Dimensions online training
Analysis by Dimensions online training   Analysis by Dimensions online training
Analysis by Dimensions online training
 
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
 
MaxTECH Technical Training Presentation from MaximoWorld 2018
MaxTECH Technical Training Presentation from MaximoWorld 2018MaxTECH Technical Training Presentation from MaximoWorld 2018
MaxTECH Technical Training Presentation from MaximoWorld 2018
 
Birt (business intelligence and reporting tools)
Birt (business intelligence and reporting tools)Birt (business intelligence and reporting tools)
Birt (business intelligence and reporting tools)
 
Creating modeled views
Creating modeled viewsCreating modeled views
Creating modeled views
 
Remedy Presentation
Remedy PresentationRemedy Presentation
Remedy Presentation
 
An introduction to hyperion public sector planning
An introduction to hyperion public sector planningAn introduction to hyperion public sector planning
An introduction to hyperion public sector planning
 

Recently uploaded

Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
pchutichetpong
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
vcaxypu
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Linda486226
 
Machine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptxMachine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptx
balafet
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
slg6lamcq
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 

Recently uploaded (20)

Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
 
Machine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptxMachine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptx
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 

Analytics with Power BI and R

  • 1. Analytics with Power BI & R - Hands on Session Naresh Jasotani Email: njasotani@miraclesoft.com Director - Data & Analytics Services Miracle Software Systems Inc. October 2017
  • 2. 2 | P a g e Table of Contents 1. Introduction .........................................................................................................................................3 2. Prerequisite..........................................................................................................................................3 3. Hands On #1.........................................................................................................................................3 3.1. Download the data .....................................................................................................................3 3.2. Open Power BI............................................................................................................................3 3.3. Import the data in Power BI.........................................................................................................3 3.4. Visualize the data........................................................................................................................5 3.5. Understand the data and trends ..................................................................................................7 4. Hands On #2.........................................................................................................................................7 4.1. Creating a R visual.......................................................................................................................7 4.2. Creating a Boxplot using R visual................................................................................................10 4.3. Create a ggplot using R visual.....................................................................................................11 5. Hands on #3 .......................................................................................................................................12 5.1. Time series forecasting using ARIMA alogrithm ...........................................................................12 5.2. Time series forecasting using custom visual ................................................................................13 5.3. Creating a predicted data table from R – ARIMA algorithm ..........................................................14
  • 3. 3 | P a g e 1. Introduction Analytics with Power BI and R - A Hands on session Organizations are looking to transform their data processing efforts into analytics and reports, which gives them real-time insights into their business using machine learning and R recently. Microsoft power BI as a self-service BI tool, which defines an approach for enabling self-service analytics helps people to easily extract data from different sources, apply data transformation for visualizing data in an appropriate way. R become a language for data analysis and machine learning. Recently, Microsoft enabled users to use R codes and visuals inside the Power BI. These hands on exercises are designed to get you started with R codes, and visuals in Power BI. 2. Prerequisite  Please bring your own laptops, with at least 4 GB of RAM. Laptop should be enabled to connect to Wi-Fi or internet using mobile hot-spot.  Please download and install the Power BI Desktop software from the location below: https://powerbi.microsoft.com/en-us/desktop/ 3. Hands On #1 3.1. Download the data  Download the csv data from the following location, save it on your C: drive. https://drive.google.com/open?id=0B-RQ0-9g-k1lWVdrVzBYN3BQQms  Create a folder C:R  The csv file should be available at this location – C:RRetail_Sales_Data.csv 3.2. Open Power BI From the Desktop (or from the start menu) click on the following icon to launch the Power BI Desktop 3.3. Import the data in Power BI  Close the Sign-in window page if prompted, after opening the Power BI.  Click on Get Data option on the under the Home Menu, and then select More.
  • 4. 4 | P a g e  Click on Text/CSV, Click on Connect. Navigate to C:RRetail_Sales_Data.csv.
  • 5. 5 | P a g e  Click on Load 3.4. Visualize the data  On the right hand side Fields Menu, you would see a list of columns, as shown in the screenshot below.  Click on the checkbox next to SalesDate, Sales_Amt columns.  Click on the small arrow next to SalesDate in the Visualizations section. Select the SalesDate instead of Date Hierarchy.  Click on the Line Chart from the Visualizations section (1st icon on the 2nd Row)  Click anywhere on the page (white space outside the line chart, so that the line chart is not selected).  Select the checkbox next to ItemName under the Fields section.
  • 6. 6 | P a g e  You would see a list of Item Names appearing on Page. Move the ItemName section on the right side.  Adjust the Line Chart to look something like this. Select the ItemName list section on the right, and then select the Slicer (Filter Icon on the last row, 1st Icon) from the Visualization Section.  Change the text size of the ItemName Slicer to 12 from the the Visualization Section Navigation shown below.
  • 7. 7 | P a g e 3.5. Understand the data and trends  Select Think Pad 450s from the Slicer, and see the trend against time.  Select the Line Chart, and then select the Sales_Cost from the Fields.  From the top ribbon, under Home Menu, select Text Box, and add the heading - Daily Sales Trend. 4. Hands On #2 4.1. Creating a R visual  Create a new page by clicking on the + icon for the new page, at the bottom left side of the window. A new Page-2 is created.  Add a Slicer for ItemNames similar to the slicer in Page-1 (steps included in the above Hands on #1 section)  In the Visualization section, in the last row of the available charts, find the R script visual.  Click on the R script visual, then click on the Enable button, as shown below. Please note that if you don’t have R installed on your system, then download and install R from the following location: https://mran.revolutionanalytics.com/open/
  • 8. 8 | P a g e  The R visual will look something like this. Select Sales_Amt, Sales_Cost and Sales_Qty from the Fields section.
  • 9. 9 | P a g e  In the R script section of the visual, copy-paste the following code, and then click Run Script. Please note that you have to install.packges(‘ggplot2’), if you haven’t used ggplot2 package before. library(ggplot2) t<-plot(dataset)  Select Think Pad 450s from the slicer option. The plot would look like this: Congratulations!! You have successfully ran R script from Power BI.
  • 10. 10 | P a g e 4.2. Creating a Boxplot using R visual  Select another R visual on the same page, and then select ItemName, Sales_Qty and Discount.  Then write the following piece of code, in the R script area; then click on Run Script. boxplot(dataset$Sales_Qty, main="Boxplot", ylab="Sales_Qty")  Select Think Pad 450s from the slicer option. The plot would look like this:  To find a correlation between Sales_Qty and Discount, use # symbol to comment out the first line of code, then add the following piece of code, in the R script area; click on Run Script. Observe that the correlation between Discount and Sales_Qty #boxplot(dataset$Sales_Qty, main="Boxplot", ylab="Sales_Qty") boxplot(Discount~Sales_Qty,data=dataset, main="Boxplot", ylab="Sales_Qty")
  • 11. 11 | P a g e 4.3. Create a ggplot using R visual  Install the ggplot2 package using the R console. install.packages(‘ggplot2’)  Go back to Power BI, then create a new page by clicking on the + icon for the new page, at the bottom left side of the window. A new Page-3 is created.  In the Visualization section, in the last row of the available charts, find the R script visual.  Click on the R script visual, then click on the Enable button, as shown below.  Select another R visual on the same page, and then select ItemName, Sales_Qty and Discount.  Then write the following piece of code, in the R script area; then click on Run Script. library(ggplot2) ggplot(dataset, aes(x = ItemName , y = Sales_Qty,fill = ItemName )) + geom_bar(width = 0.85, stat="identity")
  • 12. 12 | P a g e 5. Hands on #3 5.1. Time series forecasting using ARIMA alogrithm  Create a new page by clicking on the + icon for the new page, at the bottom left side of the window. A new Page-4 is created.  Add a Slicer for ItemNames similar to the slicer in Page-1 (steps included in the above Hands on #1 section)  In the Visualization section, in the last row of the available charts, find the R script visual.  Click on the R script visual, then click on the Enable button, as shown below.  Select another R visual on the same page, and then select SalesDate, Sales_Amt.  Then write the following piece of code, in the R script area; then click on Run Script. Please install forecast and tseries R-packages if not already installed. library(forecast) library(tseries) ARIMA_Sales<-ts(dataset$Sales_Amt,start=c(1)) Sales_Forecast<-auto.arima(ARIMA_Sales, seasonal=TRUE) Predicted_Sales<- forecast(Sales_Forecast, h=10) plot(Predicted_Sales)
  • 13. 13 | P a g e 5.2. Time series forecasting using custom visual  Create a new page by clicking on the + icon for the new page, at the bottom left side of the window. A new Page-5 is created.  Add a Slicer for ItemNames similar to the slicer in Page-1 (steps included in the above Hands on #1 section)  From the Visualization section, click on the (…), and then select Import from store option. Please note that you need a Power BI account. You can sign-up for a free account using your corporate email id on powerbi.com  From the Advanced Analytics section, click on Add button against Forecasting with ARIMA.  You will see an additional visual appearing in the Visualizations section.  Click on the Forecasting with ARIMA visual, and then drag and drop the SalesDate in the Date section of the visual, and the Sales_Amt in the values section. Please be patient, it may take a few minutes to load.
  • 14. 14 | P a g e 5.3. Creating a predicted data table from R – ARIMA algorithm  Click on Edit Queries from the Home menu on the top of the window. A new window opens up like this.  In the Query Editor, click on the New Source -> More from the top of the window, and then click on the R Script.  Enter the following code in the R editor window. Please install forecast and tseries R- packages if not already installed. dataset <- read.csv('C:RRetail_Sales_Data.csv', header=TRUE, stringsAsFactors=FALSE) library(forecast) library(tseries) ARIMA_Sales<-ts(dataset$Sales_Amt,start=c(1)) Sales_Forecast<-auto.arima(ARIMA_Sales, seasonal=TRUE) Predicted_Sales<- forecast(Sales_Forecast, h=10) plot(Predicted_Sales) Predicted_Sales_Table <- data.frame(Predicted_Sales)
  • 15. 15 | P a g e  In the Navigator window, you would see an option to select the data or the output Predicted_Sales_Table. Select the second one.
  • 16. 16 | P a g e  You would see the predicted output table is added to the data model. Congratulations!! You have successfully learnt various methods of executing R scripts from Power BI.