One of my favorite tricks in Power BI is to use R integration to quickly export data outside of Power BI. This is also a very popular question among Power BI enthusiasts. Once users realize the true capabilities and easy of the Power Query editor to transform and clean data they want to clean up their files using Power BI but the challenge is then how do I get the data out?
Update: Video embedded at bottom of blog post.
Prerequisite – R
If you want to test this method out you need to install R on your machine, for your convenience see the following link:
https://mran.microsoft.com/open/
Export data from Power BI using R
Like all of my quick tip blogs, this will be quick .
You will export data from the Power Query Editor. To launch the Power Query Editor click Edit Queries from the Home ribbon in Power BI.
Inside the Power Query Editor, click the transform ribbon and then click on R.
Once you click on the large letter R seen in the screenshot below a new window will open. Now you just have to type in some basic code. Here is the pseudo code:
write.csv(dataset, <destination>)
That’s it! Click ok and check your folder for the file. Do notice that I used two backslash characters, this is required. The other question I get is can I write the results to an excel file or to a SQL Database table and the answer is…. Yes! R has packages that make doing particular tasks easier and if you want to write to an Excel file or SQL Server table you would need to install those packages. My hope is to do some follow-up post around this topic.
Thanks for checking out my blog!
Pingback: Using R to unzip and process files into Power BI – Mitchellsql
Pingback: PASS Summit–Lightning Talk on R – Mitchellsql
is there a limit on the number of lines exportable?
Hey Dan, If there is a limit I haven’t ran into it!
I used to write 9 000 000 no issues
Is there a way to write the script so that the exported file gets saved to a SharePoint Online site (NOT Sharepoint OnPremise)?
Hey Casandra, I’m not sure exactly how you would do this. I would probably just write the file on-prem with Power BI then use Power Automate to move it anywhere else I might want it 🙂 However, I did find this article after a quick search that makes me think it is possible with R.
https://stackoverflow.com/questions/41895673/saving-a-file-to-sharepoint-with-r