Using the Power BI Service as a data source in Excel

Using the Power BI Service as a data source in Excel
Photo by Ginevra Austine / Unsplash

We want to create reports based on data that we have in a semantic model in the cloud but we still need a certain degree of working with the data instead of just consuming it.

We may also want to just use the data from the semantic model as a data source that we can combine with formulas or even Power Query in Excel.


Why:

Power BI reports are awesome, they offer a vast variety of features that allows its developers to create beautiful and meaningful visualizations. However, reports are known for their rigidity - but sometimes, a little flexibility is needed. In this case, Excel still excels with its ability to import data from various sources.

Currently, Excel lacks the possibility of querying data from a semantic model in the Power BI Service via Power Query. This is due to the tabular model structure of Power BI semantic models in comparison to other data sources.


Quick foreword:

In this tutorial I assume that you already have basic skills in DAX coding. You will need it because the Power BI Service is queried using DAX code to get data out of the semantic model in the cloud.


Step by step:

  1. Open Excel and click on “Data”. Use the “Get Data” menu to navigate to “From Fabric & Power Platform” to find the “From Power BI” option:
  1. Klick on the Power BI option and klick on “+ Insert Table” to create the template we will use:
  1. Import any column you want, choose sample data but the fewer the faster. In this example I just import the date column from my calendar table:
We do this to establish a connection that we can later reuse for our own query. If you just need a static table from the model, you can select the needed columns and measures and this tutorial could be finished for you after step 7.
  1. The preview now shows sample data:
  1. Use “Insert Table” to import the generated table in Excel:
  1. Just wait until the loading step completes:
  1. The sample data should now be imported and visible on a new worksheet in Excel:
  1. To see the underlying query, click the “Queries & Connections” button in the “Data” section:
  1. You will now see a rider pop up on the right side of your Excel window with your connection:
  1. Right-click the connection you just created to get to the “Properties…” menu:
  1. Here you can choose a distinct name or description you would like your query/table to have ("Connection name:"/"Description:"). But we want to go to the “Definition” section of the Pop-Up-menu:
  1. Search for the “Command text:” box. There you will find your DAX table definition:
This DAX code was automatically generated when you selected your columns and measures as you imported the data in step 5.
  1. You may copy that DAX query and paste it into your DAX Studio instance. Executing the query leads to the following result:
If you are new to DAX, tinker a little bit with new code that you add or by renaming variables to see the effect on the result table.
  1. You can delete the DAX code in the “Command text:” box and fill it with your own DAX code. From here you can use the data in your Excel file to create reports that depend on that data. You can even use Power Query to use the imported data and altering it further (e.g. if you want to un-/pivot columns or something like that).
Consider saving the Excel file as a template file so your original operational report does not get harmed by people using it. The automated refresh option (described later) will suit you well if you want to always guarantee fresh data.
  1. If you want to refresh the data in the table, you can use multiple methods:

First method

Use right-click to open the context menu and click on the "Refresh" entry:

Second method

Use refresh button in the "Data" rider:

"Refresh" option is only available if your cursor is located in one cell of the table like visible in the screenshot for the first method. Instead, "Refresh All" will be displayed - but sometimes you do not want to refresh all data in an Excel file.

Third method:

Use the automated refresh every time this file opens up. Repeat step 8-10 to get to the following menu and hit the "Refresh data when opening the file" button:

Keep in mind, that this applies to every person that opens this file. If the person (the persons user) does not have access to the semantic model, there will be no data returned. This means, it will be "empty" after the refresh cycle ends.

A few things to consider:

  • If you alter the structure of the table like deleting a column, this will irrevocably delete alter the structure of the table. There is no way of recovering the original structure of the table without either pressing “CTRL + Z” or recreating the whole steps.
  •  If you build a report in Excel, you may do not want that some data sources are automatically refreshed when the third method is activated. In the "Connection Properties" (Step 8-10) you can deactivate the "Refresh this connection on Refresh All" so that it

One last thing:

If your company uses the "Analysis Services" with Power BI Report Server on-premise, you can use the CUBE formulas in Excel to access the data model. With this, importing data and creating Excel-Reports that are more flexible is far more comfortable.

This is a huge advantage of an "on-premise Power BI installation".

Liked this article? Hit me up with a private message on LinkedIn to discuss it or leave feedback.