Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Extending Power BI with Python and R
Extending Power BI with Python and R

Extending Power BI with Python and R: Perform advanced analysis using the power of analytical languages , Second Edition

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Extending Power BI with Python and R

Configuring R with Power BI

Power BI Desktop is not equipped with the analytical language engines presented in the previous chapter by default. Therefore, it is necessary to install these engines and properly configure Power BI Desktop to correctly interface with them. It is also recommended to install an Integrated Development Environment (IDE), enabling you to work in the way you are most comfortable.

We’ll look at how to get those engines up and running and give you some general guidelines on how to pick the most appropriate one for your needs. After that, we’ll look at how to make these engines interface with both Power BI Desktop and the Power BI service.

Finally, we will give some important tips on how to overcome some stringent limitations of R script visuals within the Power BI service.

In particular, this chapter will deal in detail with the following topics:

  • The available R engines
  • Choosing an R engine to install
  • Installing...

Technical requirements

This chapter requires you to have a working internet connection and Power BI Desktop already installed on your machine. It also requires you to have signed up for the Power BI service in the last part of the chapter (here’s a how-to: http://bit.ly/signup-powerbiservice). A Power BI free license is enough to test all the code in this book, as you will share reports only in your personal workspace.

The available R engines

There is more than one R distribution available on the market that you can use for free for your advanced analytics projects. In this section, we’ll explore the main details of each of them.

The CRAN R distribution

When it comes to installing the R engine, we almost always think of the open source software environment, par excellence, developed by a collective of contributors over the years known as CRAN R, also called base R (https://cran.r-project.org). To be exact, the Comprehensive R Archive Network (CRAN) is a network of web servers and FTP servers around the world whose goal is to preserve multiple identical and up-to-date versions of the R source code and the entire ecosystem of R packages developed by the community, along with all the R documentation.

One of the biggest advantages of CRAN R is its very active community of developers. Their contribution to the creation of new packages on CRAN is invaluable. That’s why if you...

Choosing an R engine to install

Once it is decided that CRAN R is the R distribution to adopt, the first question when installing an R engine is: “Which version should I install? Do I choose the latest one, or do I opt for a previous one?” The usual answer to these kinds of questions is: “It depends!” In our case, the goal is to use the R engine within Power BI, so we need to understand which versions are used by the various products that admit the use of R within them.

The R engines used by Power BI

We saw in Chapter 1, Where and How to Use R and Python Scripts in Power BI, that only two Power BI products are allowed to use scripts in R and Python: Power BI Desktop and the Power BI service (remember that Power BI embedded is implicitly included when talking about the Power BI service). So, the answer “It depends!” has a clearer connotation now: if you need to share your reports with people inside your organization, then you have to...

Installing an IDE for R development

The need to install a state-of-the-art R IDE for the development of code in Power BI comes from the need to have all the tools necessary to identify any bugs and quickly test the results of code chunks on the fly.

TIP

It is strongly suggested to test your R code in the IDE and verify the results before using it in Power BI.

There are many IDEs for R development on the market. Some examples are R-Brain IDE (RIDE), IntelliJ IDEA, and JupyterLab, but it is estimated that over 90% of R programmers use RStudio as their primary IDE because of the countless features that simplify their daily work. For this reason, we suggest that you also use this IDE to test the code you will encounter in this book.

Installing RStudio

Installing RStudio (at the time of writing the chapter, the version is 2022.07.2+576) on your machine is very simple:

  1. Go to https://posit.co/download/rstudio-desktop/ and click the DOWNLOAD RSTUDIO...

Configuring Power BI Desktop to work with R

Once you have installed the R engines necessary for the development of your reports and the RStudio IDE, you must configure Power BI Desktop so that it properly references these tools. This is really a very simple task:

  1. In Power BI Desktop, go to the File menu, click on the Options and settings tab, and then click on Options:
Figure 2.14 – Opening the Power BI Desktop Options and settings window

Figure 2.18: Opening the Power BI Desktop Options and settings window

  1. In the Options window, click on the R scripting tab on the left. The contents of the panel on the right will update, giving you the option to select the R engine to reference and the R IDE to use for R script visuals:
Graphical user interface, text, application  Description automatically generated

Figure 2.19: Choosing the engine and the IDE to work with in Power BI Desktop

  1. As you can see, Power BI Desktop automatically identifies the installed R engines and IDEs. For the moment, select the latest version of the engine (in our case, it is 4.2.2), in order to be aligned...

Configuring the Power BI service to work with R

As you learned in the The R engines used by Power BI section of this chapter, the Power BI service uses different R engines depending on whether the scripts are used in R script visuals or in Power Query for data transformation. In the first case, the engine is pre-installed on the cloud.

IMPORTANT NOTE

If the data sources of your report come exclusively from online services (e.g., Azure SQL Database) or the web, and if the R scripts in your report are used only in the R script visuals, you don’t need to install the data gateway in personal mode to refresh the datasets.

In the second case, or if at least one dataset in your report is fed from an on-premises data source or on an Azure VM, you need to install the on-premises data gateway in personal mode on any machine of your choice in order to make the Power BI service communicate with the R engine you installed on that machine.

Installing the on...

R script visuals limitations

R script visuals have some important limitations regarding the data they can handle, both as input and output:

  • An R script visual can handle a data frame with only 150,000 rows. If there are more than 150,000 rows, only the first 150,000 rows are used and a relevant message is displayed on the image.
  • R script visuals have an output size limit of 2 MB.

You must also be careful not to exceed the 5 minutes of runtime calculation for an R script visual in order to avoid a time-out error. Moreover, in order not to run into performance problems, note that the resolution of the R script visual plots is fixed at 72 DPI.

As you can imagine, some limitations of R script visuals are different depending on whether you run the visual on Power BI Desktop or the Power BI service.

If you think you need to develop reports intended only for Power BI Desktop, without the need to publish them on the service, you can do any of the following...

Summary

In this chapter, you learned about the most popular free R engines in the community. In particular, you learned about the performance advantages introduced by Microsoft in its distribution of R, even if this distribution will be retired in the near future. You also learned how to enhance the standard CRAN R with the oneMKL libraries for multi-threaded calculations.

Taking note of the unique features of Power BI Desktop and the Power BI service, you have learned how to properly choose the engines and how to install them.

You have also learned about the most popular IDE in the R community and how to install it.

In addition, you were introduced to all of the best practices for properly configuring both Power BI Desktop and the Power BI service with R, whether in a development or enterprise environment.

Finally, you learned about some of the limitations of using R with Power BI, knowledge of which is critical to avoid making mistakes in developing and deploying...

Test your knowledge

  1. What are the most popular R engines to date and which of them will be phased out?
  2. What is the most obvious advantage of Microsoft’s R distributions?
  3. Is it possible to introduce the advantage in question 2 for CRAN R as well? If so, can this be done directly from the software installer?
  4. You decide to install the latest available version of CRAN R, and through this, you develop some transformation steps in Power Query. What do you need to be able to publish your report to the Power BI service and allow it to be refreshed regularly?
  5. Suppose you have installed only the R engine mentioned in Question 4 and you also add a plot made with an R script visual to the same report mentioned in Question 4. What are the problems you’ll encounter on Power BI Desktop? What are the problems you’ll encounter when you publish the report to the Power BI service?
  6. Is it possible to refresh datasets of a published report using...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Discover best practices for using Python and R in Power BI by implementing non-trivial code
  • Enrich your Power BI dashboards using external APIs and machine learning models
  • Create any visualization, as complex as you want, using Python and R scripts

Description

The latest edition of this book delves deep into advanced analytics, focusing on enhancing Python and R proficiency within Power BI. New chapters cover optimizing Python and R settings, utilizing Intel's Math Kernel Library (MKL) for performance boosts, and addressing integration challenges. Techniques for managing large datasets beyond available RAM, employing the Parquet data format, and advanced fuzzy matching algorithms are explored. Additionally, it discusses leveraging SQL Server Language Extensions to overcome traditional Python and R limitations in Power BI. It also helps in crafting sophisticated visualizations using the Grammar of Graphics in both R and Python. This Power BI book will help you master data validation with regular expressions, import data from diverse sources, and apply advanced algorithms for transformation. You'll learn how to safeguard personal data in Power BI with techniques like pseudonymization, anonymization, and data masking. You'll also get to grips with the key statistical features of datasets by plotting multiple visual graphs in the process of building a machine learning model. The book will guide you on utilizing external APIs for enrichment, enhancing I/O performance, and leveraging Python and R for analysis. You'll reinforce your learning with questions at the end of each chapter.

Who is this book for?

This book is for business analysts, business intelligence professionals, and data scientists who already use Microsoft Power BI and want to add more value to their analysis using Python and R. Working knowledge of Power BI is required to make the most of this book. Basic knowledge of Python and R will also be helpful.

What you will learn

  • Configure optimal integration of Python and R with Power BI
  • Perform complex data manipulations not possible by default in Power BI
  • Boost Power BI logging and loading large datasets
  • Extract insights from your data using algorithms like linear optimization
  • Calculate string distances and learn how to use them for probabilistic fuzzy matching
  • Handle outliers and missing values for multivariate and time-series data
  • Apply Exploratory Data Analysis in Power BI with R
  • Learn to use Grammar of Graphics in Python

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 29, 2024
Length: 814 pages
Edition : 2nd
Language : English
ISBN-13 : 9781837639533
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Mar 29, 2024
Length: 814 pages
Edition : 2nd
Language : English
ISBN-13 : 9781837639533
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 121.97
Mastering Microsoft Power BI – Second Edition
€37.99
The Definitive Guide to Power Query (M)
€41.99
Extending Power BI with Python and R
€41.99
Total 121.97 Stars icon

Table of Contents

24 Chapters
Where and How to Use R and Python Scripts in Power BI Chevron down icon Chevron up icon
Configuring R with Power BI Chevron down icon Chevron up icon
Configuring Python with Power BI Chevron down icon Chevron up icon
Solving Common Issues When Using Python and R in Power BI Chevron down icon Chevron up icon
Importing Unhandled Data Objects Chevron down icon Chevron up icon
Using Regular Expressions in Power BI Chevron down icon Chevron up icon
Anonymizing and Pseudonymizing Your Data in Power BI Chevron down icon Chevron up icon
Logging Data from Power BI to External Sources Chevron down icon Chevron up icon
Loading Large Datasets Beyond the Available RAM in Power BI Chevron down icon Chevron up icon
Boosting Data Loading Speed in Power BI with Parquet Format Chevron down icon Chevron up icon
Calling External APIs to Enrich Your Data Chevron down icon Chevron up icon
Calculating Columns Using Complex Algorithms: Distances Chevron down icon Chevron up icon
Calculating Columns Using Complex Algorithms: Fuzzy Matching Chevron down icon Chevron up icon
Calculating Columns Using Complex Algorithms: Optimization Problems Chevron down icon Chevron up icon
Adding Statistical Insights: Associations Chevron down icon Chevron up icon
Adding Statistical Insights: Outliers and Missing Values Chevron down icon Chevron up icon
Using Machine Learning without Premium or Embedded Capacity Chevron down icon Chevron up icon
Using SQL Server External Languages for Advanced Analytics and ML Integration in Power BI Chevron down icon Chevron up icon
Exploratory Data Analysis Chevron down icon Chevron up icon
Using the Grammar of Graphics in Python with plotnine Chevron down icon Chevron up icon
Advanced Visualizations Chevron down icon Chevron up icon
Interactive R Custom Visuals Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(30 Ratings)
5 star 96.7%
4 star 3.3%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Joseph C. Seroski Apr 01, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a good reference to understand how you can use Python and R in Power BI. It has a good introduction to getting setup and some great examples as to how you can extend your reports and advance your skills using these two programming languages.I enjoyed this book brings a unique perspective that I haven't seen in many other Power BI books. I am looking forward to getting more into the Python language, and this book will be helpful, especially with all the functionality coming to Fabric. I recommend this book to add another feather to your cap.
Amazon Verified review Amazon
Thomas Rice Aug 03, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
"Extending Power BI with Python and R" is a comprehensive and practical guide for enhancing data analysis capabilities in Power BI. With detailed explanations, practical examples, and step-by-step instructions, this book is an essential resource for anyone looking to integrate R and Python into their Power BI workflows. Whether you're a beginner or an experienced user, this book provides valuable insights and practical tips for maximizing the potential of Power BI. As an avid book worm, having read more than 30 books on the Microsoft Power Platform, this one is a must for anyone that works with Power BI. Highly recommended guys!
Amazon Verified review Amazon
Arden Jul 26, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book author has a strong hold over the Powerbi community and even the technology I believe this book is beneficial for people who have had a strong command over the Power BI, R and Python space because of the diversity it brings throughout the chapters, the most important thing is the journey of different libraries and how it has affected the whole space and how the case studies have been shared throughout the book. Congratulations to the authors for binding in a book of such quality!
Amazon Verified review Amazon
Sruthi Panikar Apr 16, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book for anyone interested in python and r at the same time loved the book its an amazing title!
Amazon Verified review Amazon
Brady Apr 03, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A great resource for Power BI users aiming to bolster their analytical prowess. The authors offer well-explained and hands-on examples, leading readers through the intricacies of seamlessly integrating Python and R with Power BI.I was particularly drawn to the Python side of this book. I've often found using Python visuals or features in Power BI to be cumbersome. My visuals would load slowly, prompting me to revert to default visuals in Power BI and stick to traditional M query data transformations.This book opened up some possibilities I'd never considered where in the past I'd given up trying to implement. Python has much more appealing visuals and data capabilities but I didn't know how to use it without seemingly bogging down my entire report. As a heavy Power BI user, I got a lot of new ideas to consider from this book.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.