Summary
This chapter has given a detailed overview of all the ways in which you can use R and Python scripts in Power BI Desktop. During the data ingestion and data transformation phases, Power Query Editor allows you to add steps containing R or Python code. You can also make use of these analytical languages during the data visualization phase thanks to the R and Python script visuals provided by Power BI Desktop.
It is also very important to know how the R and Python code will interact with the data already loaded or being loaded in Power BI. If you use Power Query Editor, both when loading and transforming data, the result of script processing will be persisted in the data model. Also, if you want to run the same scripts again, you have to refresh the data. On the other hand, if you use the R and Python script visuals, the code results can only be displayed and are not persisted in the data model. In this case, script execution occurs whenever cross-filtering is triggered via the other visuals in the report.
Unfortunately, at the time of writing, you cannot run R and Python scripts in every Power BI product. The only ones that provide for running analytics scripts are Power BI Desktop and the Power BI service.
In the next chapter, we will see how best to configure the R engine and RStudio to integrate with Power BI Desktop.