Updated: 10 Nov 2020
I first wrote this article about how to import Tabular Data from Power BI into Excel back in Jan 2017. The benefits of extracting tabular data are still the same as they were back then however the process of extracting the tabular data from Power BI has changed. This update today re-presents the concept and shows the current process to complete the task.
What Problem Does this Solve?
Let’s assume you want to get a table of data from your data model, eg a printable list of customers with their annual sales year to date. Let’s say that there are 50,000 customers. How do you do this?
- You can create a table visual in Power BI, but you can’t print it from Power BI.
- You can’t export it to Excel because there is a 30,000 row limit. Besides, doing so will mean the data will go stale.
- You could use paginate reports, but that is a premium feature; besides, that is a whole new area for many people.
- The standard Analyze in Excel can only view the data in Excel via a pivot table, not a table of records. It “can” work, but it is clunky (in my view).
- You could download the Power BI Desktop file to your PC and use DAX Studio, but you have to download the entire model just to get the records you want.
Create an Excel Table Connected to Power BI
This technique allows you to write a DAX Query and run that from within an Excel workbook table with a live connection back to an online Power BI Dataset. The example I am going to use in this article about extracting tabular data from Power BI is to create the below table of Products by Colour with the total sales for each colour. I am using this as a demo to show you how to do it. If I actually wanted to build this table, I would frankly just use a pivot table. But it is the concept I want to show, not the outcome.
The steps to complete this process so you can import your tabular data from power bi are.
- Create the connection to your PowerBI.com data source
- Create a table that links to the source
- Write the DAX query that gives you table you want
Here is a walk through.
Create a Link to PowerBI.com
There are a few ways you can do this. You could use Analyze in Excel to create the link starting from PowerBI.com.
- Select the dataset from the Power BI Service
- Click the overflow menu
- Select Analyze in Excel
- Power BI will download an Excel Workbook with a connection to your Power BI dataset online.
The other way is to start from Excel. Note: This is only available in the most recent versions of Excel. If you don’t see the feature below, you should use the Analyze in Excel approach mentioned above.
You can directly connect to a Power BI Data Set from within Excel. Start with a brand new Excel file, go to the data menu and click on Get Data (#1 below). Then select From Power BI (#2 below).
Go to Power BI Datasets (#1 below) and then select the dataset you want to use (#2 below).
The Power BI data model gets connected to Excel and an empty shell of a pivot table appears on the worksheet.
Create a Table that Links to Power BI
This is where the secret sauce is. The easiest way to extract tabular data from Power BI by creating an Excel Table linked to Power BI is to first create a pivot table. Just create anything simple, like this.
Actually, you don’t even need the years, you can just add any measure into the values section, and that’s it.
Double click on any one of the data points in the pivot table. When you do this, Excel will create an Excel table showing you all the records that make up the value in the pivot table.
This new table has an underlying connection to the Power BI Service. You can now delete the pivot table sheet – it is not needed anymore.
Write the Query
To do this next step, you need to learn a bit of the DAX Query Language. I am not going to go into the DAX Query language in detail in this post as I cover that extensively in other blog articles. This one is a good place to start. I will simply show how to edit the current table code so you can build the table you need.
To edit the query, I simply right clicked anywhere in the table (#1 below), then selected Table (#2 below), then Edit Query (#3 below).
This brings up a dialog like the one below. The connection string at the top can be edited if needed, eg if you want to change the connection to a different report. The command text that you can see at the bottom can be deleted and replaced with any valid DAX table query.
To demonstrate, I could write a simple DAX query as follows.
After clicking OK, the query is executed against the service and the table (Products in this case) is returned to Excel.
Total Sales by Product Colour
Next, to get total sales by product colour, I edited the query as shown below.
Here is my query
ADDCOLUMNS ( ALL ( Products[Color] ), “Sales”, [Total Sales] )
And this gave me a table of all product colours and the total value of sales for those products as shown below.
I could have used SUMMARIZE instead of ALL to get only the colours with sales.
Interestingly the number formatting for Total Sales did not flow through to Excel as I expected it to. First I thought this was a bug, but the more I thought about it, the more I think this is “working as designed”. The representation of the Sales above is actually not the measure [Total Sales] that has the formatting. It is actually a new column projection in a new table that uses the Measure as an input. The new column clearly does not inherit the formatting from the measure. It would be useful it if it did, but think about the following query.
ALL ( products[color] ),
“Markup %”, DIVIDE ( [Total Sales], [Total Cost] ) – 1
The above query returns a % markup as the new column. The measures [Total Sales] and [Total Cost] are both formatted as $ with zero decimal. So how will the query know to return % as the number format? I therefore think this is working as designed. The good news is that if you apply the formatting you want to the entire column of the new table, the formatting will be applied to all values in that column even if the column grows or shrinks on a future refresh.
Once you extract the tabular data and finally have a table, you can use the Excel print capabilities to turn this into a paginated report (if you want to). Eg you can repeat the headers on each printed page, etc. To refresh the table, just right click on the table and select “Refresh”.
If you finally know how to import tabular data from power bi and would like to learn more about DAX as a query language, you can check out my series of articles that starts here An Introduction to DAX as a Query Language