Tuesday, 27 February 2018

Integrating R with Power BI

I am fairly new to both Power BI and R. I know Power BI can be easily integrated with R, and there is Visualization available for that also. Therefore it would be great if can use both R and Power BI together.

First, I have checked that if my R script options are proper or not. Here I have set my R home directory and R IDE. With respect to R IDE (Integrated Development Environment), I will be explaining later.


Just to confirm I have 2 R directories and in this case I am going to use the 3.4.2, and the path correctly set in Power BI.

Next I add the R visual in Power BI.


It might ask you to enable it.


Now once it is added, there will be a R script editor available at the bottom.


For the purpose of the demo, I am using one csv file, I have received from a R training from Udemy (to confirm this is purely for demo purpose).

This csv contains 3 columns: carat (Diamond Carat), clarity (Diamond Clarity) and price (Diamond Price). Our objective is to prepare a visualization, to depict if the price is always proportional with the Carat and Clarity.


I add these 3 columns in the values for the R visualization, and you can notice a Dataset cotaining the columns gets created automatically.


Next for the purpose of my visualization I un-summarize carat and price. These are numeric field, and Power BI adds the aggregation by default.


Now before I start writing the code in the editor, let me go back to R IDE. There is a option on the top right of the editor, to open it is R IDE. What it will do is open the R Studio (as that is set as the R IDE for me), and I can do the coding in R Studio.


Going back to the objective creating a visualization to depict if the price is always proportional with the Carat and Clarity.

I have this piece of code in R Studio, which use ggplot, to create this chart.


Now I just copy and paste this code in the R Script Editor in Power BI. I just do minor change in the dataset portion.


When I run the code I get the same chart. And the best part is now I can use the additional Power BI capabilities like Slider etc with this.

1 comment:

  1. Great post! Very informative and clearly explained. Thanks for sharing such valuable content. If anyone is looking to upskill in PowerApps and Power Automate, we offer comprehensive PowerApps and Power Automate Online Training with hands-on experience. Feel free to check it out!

    ReplyDelete

Implementing & Testing Row Level Security in Power BI

I have suffered a great deal of pain while implementing and more so while validating Row Level Security in Power BI. Let me try to capture a...