Using R Programming On Power BI Desktop

Power BI and R are two giants in the world of data but with different use cases.While Power BI is used in the field of Business Intelligence to build reports and interactive dashboards, R is a programming language for statistical analysis and data scie…


This content originally appeared on Level Up Coding - Medium and was authored by Adejumo Ridwan Suleiman

Power BI and R are two giants in the world of data but with different use cases.

While Power BI is used in the field of Business Intelligence to build reports and interactive dashboards, R is a programming language for statistical analysis and data science.

In this post, I am going to show you how you can have the best of both worlds by running your R Scripts in Power BI.

Please ensure you have Power BI Desktop and R installed on your PC before proceeding.

Importing Data

First of all, you need to get Power BI Desktop up and running and also ensure you run Power BI as an administrator.

You are going to be having a screen like the one shown above.

I am going to be using the motorcycle sales data for demonstration, you can download it here.

Or you can feel free to import your own datasets.

Click on Get data from another source -> Text/CSV -> Connect.

You should have something like this

Let’s transform the data by clicking on Transform Data.

This will open the Power Query Editor.

This is where messy data gets cleaned in Power BI, just like you taking a shower after your morning gym session, to avoid stinking the whole office like someone who just came back from a war with zombies.

Running R Scripts in the Power Query Editor

In this window, you have two options, either you clean your data like momma’s boy or you do what real men do.

I am going to go for the latter, go to the transform tab on the ribbon, click on the option Run R Scripts

After clicking, a space to write your R scripts will be provided to you

I am going to run the R script below which imports the data-set and filters only retail clients.

The key takeaways here are:

Upon clicking okay, you will get information saying your Information is required about your data privacy.

Click on continue, check on ignore privacy levels then save.

Image by Author
Image by Author

Close and apply this transformation so as to visualize the data in Power BI

Image by Author
Image by Author

Running R Scripts for Data Visualization

To create a visualization with an R script, click on the R script visual on the Visualizations pane.

You will be asked to drag the fields you will be needing in your visualization to the values area

I want to visualize the total amount made at each warehouse. I will be dragging the warehouse and total columns.

Your data has already been created by Power BI as a dataset, yours is to just provide the script that will visualize your data.

Run the script below,

library(tidyverse) 
dataset %>%
group_by(warehouse) %>%
summarize(total = sum(total)) %>%
ggplot(aes(x = warehouse, y = total, fill = warehouse)) +
geom_col()

You can create more visualizations and create a report without running any DAX query.

Conclusion

Sometimes you might want to create complex visualizations, which is easier to do on R.

This integration gives you room to build such visualizations.

Thanks for reading, hope you find the post insightful.

Originally published at http://rblogopedia.wordpress.com on October 8, 2022.

Level Up Coding

Thanks for being a part of our community! Before you go:

🚀👉 Join the Level Up talent collective and find an amazing job


Using R Programming On Power BI Desktop was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Adejumo Ridwan Suleiman


Print Share Comment Cite Upload Translate Updates
APA

Adejumo Ridwan Suleiman | Sciencx (2022-11-28T12:46:09+00:00) Using R Programming On Power BI Desktop. Retrieved from https://www.scien.cx/2022/11/28/using-r-programming-on-power-bi-desktop/

MLA
" » Using R Programming On Power BI Desktop." Adejumo Ridwan Suleiman | Sciencx - Monday November 28, 2022, https://www.scien.cx/2022/11/28/using-r-programming-on-power-bi-desktop/
HARVARD
Adejumo Ridwan Suleiman | Sciencx Monday November 28, 2022 » Using R Programming On Power BI Desktop., viewed ,<https://www.scien.cx/2022/11/28/using-r-programming-on-power-bi-desktop/>
VANCOUVER
Adejumo Ridwan Suleiman | Sciencx - » Using R Programming On Power BI Desktop. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/28/using-r-programming-on-power-bi-desktop/
CHICAGO
" » Using R Programming On Power BI Desktop." Adejumo Ridwan Suleiman | Sciencx - Accessed . https://www.scien.cx/2022/11/28/using-r-programming-on-power-bi-desktop/
IEEE
" » Using R Programming On Power BI Desktop." Adejumo Ridwan Suleiman | Sciencx [Online]. Available: https://www.scien.cx/2022/11/28/using-r-programming-on-power-bi-desktop/. [Accessed: ]
rf:citation
» Using R Programming On Power BI Desktop | Adejumo Ridwan Suleiman | Sciencx | https://www.scien.cx/2022/11/28/using-r-programming-on-power-bi-desktop/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.