4 Ways to Export Data From Power BI - Owlcation - Education
Updated date:

4 Ways to Export Data From Power BI

I have over 15 years experience in business intelligence. I currently work as a data engineer and data analyst and use Power BI daily.

Importing data into Power BI is easy using its data source connectors and custom data connectors. It is equally easy to export data from Power BI, either using the visual components, Power Query or R and Python. In this article, we will explore these different export options.

I will show you how to export data using the following methods:

  • Standard components
  • Copy Table
  • Using the R language
  • Using the Python language

I will use the following dataset https://data.world/finance/finances-of-selected-state but you are free to use any dataset that suits your purposes.

Before you can export data from Power BI, you need to enable this feature. Under Options in the File menu, select Report Settings and enable Exporting by choosing to allow user to export only summarized data or summarized and underlining data as in the screenshot below. For demonstration purposes, I will opt to export summarized and underlining data.

I will show you how to export data using the following methods:

  • Standard components
  • Copy Table
  • Using the R language
  • Using the Python language

I will use the following dataset https://data.world/finance/finances-of-selected-state but you are free to use any dataset that suits your purposes.

Before you can export data from Power BI, you need to enable this feature. Under Options in the File menu, select Report Settings and enable Exporting by choosing to allow user to export only summarized data or summarized and underlining data as in the screenshot below. For demonstration purposes, I will opt to export summarized and underlining data.

how-to-export-data-from-power-bi

Standard Components

This is the easiest. All standard components have a command to export data to the csv format. The command is available from the Focus mode button on each of the Standard Visualization components assuming you have enabled the option in the Options as I mentioned above. To demonstrate, I will import the dataset mentioned above using the Excel Data Source Connector.

If you are not familiar with importing data, follow these instructions:

  • From the ribbon menu, select Get Data
  • Then select the Excel connector (see image below)
  • Next, browse and select the dataset file
  • Finally, select the sheet Name
Excel Data Connector

Excel Data Connector

We will use the Table component (see image below) from the Standard Component palette for this example but this option is available in all Standard Visualizations.

Table component

Table component

Add fields to the table

From the list of fields on the right, add the fields that you want to export from the imported dataset. In the screenshot below, I selected all the fields from the imported dataset ( see the image below).

All fields added to Table component

All fields added to Table component

Click on the expansion button at the top as in the following screenshot (below) then the Export Data command. The data will be saved in csv format. You only need to select the location where you want to save the file.

Export Data option

Export Data option

There you have it.

Pros: It is fast and easy

Cons: There is a size limit of 30,000 records.

Copy Entire Table

Another option which eliminates the limitations from the first option is to use the “Copy Entire Table” option in the Power Query editor.

Copy Entire Table

Copy Entire Table

  1. Use the “Edit Queries” button to open the Power Query IDE
  2. Select the desired table if you have more than one
  3. From the dropdown button (see image above), select the “Copy Entire Table” command which will copy the entire contents to memory.
  4. Paste the contents into an Excel file

This is quick and easy unless your dataset is super large, then you may run into memory issues depending on the equipment you have. In which case, you will need to export the data directly to a csv file or another format like Excel, JSON or XML. I will demonstrate this option using both the R and Python languages.

Export Data using Python


Another great option to export data from Power BI is to use Python. The language is very powerful and has become the darling of the data science world. Using libraries like pandas, matplotlib, scikit-learn, numpy to name a few, allows a data scientist or a data analysis to perform very complex algorithms on data. Being a generalized language, Python has the same features as any other language including importing and export data which can be used with Power BI.

Before being able to use Python with Power BI, you need to download and install it. Use the latest version from the Python website. Opt for the 3.x platform version of the language it has better support for the newer versions of the libraries.

Configure Python in Power BI

Configure Python in Power BI

Configure Python in Power BI

Once the Python is installed, you need to head over to Power BI to configure the Python integration (see image above). Follow these steps:

  • Under Options in the File menu
  • Select the Options tab
  • Under the Global section, select the Python scripting menu item
  • Make sure both fields are filled out for the location of the Python 3 (32 or 64 bit depending on which version of Power BI you installed).
  • For the Detected Python IDE field, leave it at “Default OS program for .py files”

While using an IDE is easier to write and test your Python scripts, you can also write the Python script directly in Power BI. Follow these instructions:

  1. Click on “Edit Queries” to open the Power Query IDE
  2. On the far right, click on the “Run Python Script” button (see image below)
  3. Enter the script in the editor using the dataset as the input source
  4. The following code snippet will write the dataset to a csv file
Run Python script in Power Query editor

Run Python script in Power Query editor

d = pandas.DataFrame(dataset)

d.to_csv('C:/Users/kevin/Documents/export.csv', index=False)

You may need to install the Pandas Python library first which you can do with the following command using the Command Line editor (Windows) or Terminal (OSX/Linux/Unix):

Pip install pandas

In the above script, we use the DataFrame in pandas to define the dataset which is always represented by “dataset”. Next, we to the to csv function again from pandas to write the data to a location on your computer. The index flag is to omit using a row index when writing to the file. You also need to use forward slashes instead of the standard backslashes.

Once you run the script, the contents of "dataset" will be written to the file and location that you specified. Using the R option is very similar and actually requires even less code.

You may want to explore these options with Python and Excel. You can use one of these Python libraries to export data from Power BI by writing a script that interfaces with the Power BI API. Documentation is available at this address: https://docs.microsoft.com/en-us/rest/api/power-bi/?redirectedfrom=MSDN

Power BI-Excel Connector

Microsoft introduced the Excel connector for Power BI a while back which allows an analysis to export data from Power BI to Excel. You can download and install the connector from the Power BI portal.

To use, you need to publish your Power BI report or Dashboard to your Workspace in the Power BI portal

Export using the R language

Like the previous method, the R language has many powerful libraries and builtin functions for working with data. Again, like Python, you will need to download and install the R language before you can use it. But once installed you will need to configure it in Power BI (see image below). You can use an IDE like RStudio (separate install) or through Anaconda if you install it or, if your script is small, you can write directly in the Editor in Power BI

To export your data using R, open the Power Query editor using the “Edit Queries” button

Select the Run R Script button from the toolbar script as in image from the Transform tab

Configure R language in Power BI

Configure R language in Power BI

R script editor in Power BI

R script editor in Power BI

Add the following script to write the dataset to a csv file:

write.csv(dataset, C:\\Users\\kevin\\Documents\\limonade.csv)

One line of code, simple. Again, the dataset represents the entire contents of the selected table if you have more than one. You can use back slashes provided you use the escape character. Or, you can use the forward slash.

Conclusion

You have seen four types of export options: using the export function from a visual component, but this has limitations on large datasets; the “Copy Entire Table” option which is quick and easy from the Power Query editor; For more complex operation you can use Python or R as well.

© 2019 Kevin Languedoc

Comments

Kevin Languedoc (author) from Canada on July 02, 2020:

i would need to investigate but I would assume you can develop a custom component or add an actionable label to one of the sheets

Pavankamal Vadigi on July 01, 2020:

Hello Mr.Kevin,

First of all, thank you so much for sharing the interesting article.

Is it possible to provide a button to "Export the data to a CSV/Excel file" in Power BI?

When the end-user clicked the button, it would execute R/Python code to download the file.

The customer would really like to have a visible button to export the data.

Thanks in advance

Kevin Languedoc (author) from Canada on June 21, 2020:

You need to connect to the Power BI REST API (not desktop). From there you can connect to your dataset and export the data.

You can also try loading the data into a pandas data frame which you can then load into IDE or manipulate in memory.

guest on June 18, 2020:

hello, i would like to export a powerbi data table into my python IDE without saving it as csv ( bcz it has more than 3 million rows how can i do that ?

Kevin Languedoc (author) from Canada on April 23, 2020:

Hi Amruta

Basically, you would need to connect to your source system from Power BI using Python or R and execute a query to extract the dataset. Of course, these would mean that you have access to the source system.

Alternatives, would be to install the Excel connector for PBI and select analyze in Excel from PBI Portal

Kevin Languedoc (author) from Canada on April 23, 2020:

That would be complicated since the data is in the source system, not in Power BI

Amruta on April 23, 2020:

Is there a way to use when data is linked in Direct Query mode.

Kevin Languedoc (author) from Canada on March 02, 2020:

Yes you could add the button the Ribbon and call a R/Python program that would export the excel contains to a csv. I can write one in a couple of days

MB on March 02, 2020:

Is it possible to have button (called "Export to CSV/Excel") which when clicked would execute a R/Python code?

Our customer would really like to have a visible button to export data.

Kevin Languedoc (author) from Canada on February 15, 2020:

EgdarKicks

Sorry for late reply. It appears that your Firewall is blocking your script. If you are running from a corporate computer, please check with help desk or IT support.

Edgarkicks on November 24, 2019:

Hello sir I find very interesting your article but it doesn't work form me at least using python and R options, in both cases appears this message:

Formula.Firewall: Query '1Facturas' (step 'Run Python script') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.

Thanks for sharing your knowledge