R with PowerBI – A step by step guide approach

A lot of interests are visible everywhere how to integrate R scripts with Microsoft PowerBI dashboards. Here goes a step by step guidance on this.

Lets assume, you have some couple of readymade R code available, for example , with ggplot2 library. Lets find the following scripts performing analytics using CHOL data.

  1. Open R studio or R Package (CRAN) & install ggplot2 library first.
  2. Paste the following R script & execute it.

install.packages(‘ggplot2’)
library(ggplot2)
chol <- read.table(url(“http://assets.datacamp.com/blog_assets/chol.txt&#8221;), header = TRUE)
#Take the column “AGE” from the “chol” dataset and make a histogram it
qplot(chol$AGE , geom = “histogram”)
ggplot(data-chol, aes(chol$AGE)) + geom_histogram()

you should be able to see the visuals output like this.

3. Next, execute the following pieces of R code to find out the binwidth argument using ‘qplot()‘ function.

qplot(chol$AGE,
geom = “histogram”,
binwidth = 0.5)

4. Lets take help of hist() function in R.

#Lets take help from hist() function
qplot(chol$AGE,
geom=”histogram”,
binwidth = 0.5,
main = “Histogram for Age”,
xlab = “Age”,
fill=I(“blue”))

5. Now, add I() function where nested  color.

#Add col argument, I() function where nested color.
qplot(chol$AGE,
geom=”histogram”,
binwidth = 0.5,
main = “Histogram for Age”,
xlab = “Age”,
fill=I(“blue”),
col=I(“red”))

6. Next, adjust ggplot2 little by the following code.

#Adjusting ggplot
ggplot(data=chol, aes(chol$AGE)) +
geom_histogram(breaks=seq(20, 50, by = 2),
col=”red”,
fill=”green”,
alpha = .2) +
labs(title=”Histogram for Age”) +
labs(x=”Age”, y=”Count”) +
xlim(c(18,52)) +
ylim(c(0,30))

7. Plot a bar graph with this following code.

#Plotting Bar Graph
qplot(chol$AGE,
geom=”bar”,
binwidth = 0.5,
main = “Bar Graph for Mort”,
xlab = “Mort”,
fill=I(“Red”))

8. Next, open PowerBI desktop tool. You can download it free from this link. Now, click on Get Data tab to start exploring & connect with R dataset. 

If you already have R installed in the same system building PowerBI visuals , you just need to paste the R scripts next in the code pen otherwise , you need to install R in the system where you are using the PowerBI desktop like this.

9. Next, you can also choose the ‘custom R visual’ in PowerBI desktop visualizations & provide the required R scripts to build visuals & finally click ‘Run’.

10. Build all the R function visuals by following the same steps & finally save the dashboard.

11.You can refresh an R script in Power BI Desktop. When you refresh an R script, Power BI Desktop runs the R script again in the Power BI Desktop environment.

Use Color Codes from Option Sets in both Dynamics 365 charts and Power BI

Option Sets in Dynamics 365 has a setting for each value to specify a color code. This color code is used in the new Unified Interface in the entity specific dashboards. This is a welcome addition as it makes it more easy to persist colors to a specific value and have it be consistent throughout the charts and visuals.

With the August 2018 release of the Power BI Desktop client, we can now also do conditional formatting based on a field with a color code in Power BI reports.

Since we can query option sets directly, and get the color code into the Power BI dataset, we can now use the same color scheme more easily between the two solutions. As the option sets are queried, any updates to values, labels, and color codes in the option set, will automatically update on the Power BI side as well.

For querying the Dynamics 365 option set into Power BI, I use the Power Query (M) Builder tool for the XrmToolBox.

M365Day – Power BI: Real Time streaming information from Sensors

Yesterday (06.11.2020) I participated as speaker in “Microsoft 365 Day”. It was an online event. I hope that we can come back to talk directly. I missed the Face2Face event… 🙂

During this event, I explain how we can create in easy way our prototype with Raspberry and Grove PI and how we can stream in real time all values from sensors and show in a live telemetry dashboard. We choose Power BI for this job.

Picture from https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-live-data-visualization-in-power-bi

For all boring and configuration part, you can see this good article from Microsoft: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-live-data-visualization-in-power-bi

Here there are all parts related with Azure configuration: IOT Hub, Stream Analytics and Power BI.

You can see how Stream Analytics works. we can use different type of information as source, send to IOT Hub and process with Stream Analytics. All processed data can have as destination an Azure Service Bus, a Cosmos DB, SQL Server db, etc.

After the configuration, we can start to send in streaming all values . We decide to use Python:

Here you can see the slides: https://www.slideshare.net/algraps/powerbi-real-time-streaming-information-from-sensors

In the next days I will publish the source code on my GITHUB also