Rebind Power BI Reports

Hi everyone,

At Devscope, we've been building some powerbi powershell modules to help us deal with some situations we face with our clients on the PowerBI Service.

The scenario I'm going to share with you today is a simple one, but the work to solve it is usually painful, so I hope this will help some of you guys to avoid the trouble this used to cause us.

The Situation

My users built a bunch of reports over one or more copies of the same dataset. Then we published a new one, for instance, we migrated the old one to an Azure Analysis Services so the new dataset is live connected.

So, how do we rebind all those reports to the new model effortlessly?.

The measures and tables are all the same, but we must avoid copying all the pages manually to the new dataset, because who wants to do that?

The Solution

Power BI REST API has a very cool operation called 'Rebind Report', so we built a script to make the most out of it in the easiest way possible with a powershell script. The end result is the following:

# This will install and import our PowerBI PS module
Install-Module PowerBIPS -Scope CurrentUser

# Then we authenticate to PowerBI, you can use -ForceAskCredentials to change the cached login
$authToken = Get-PBIAuthToken #-ForceAskCredentials

# After thet, we define the workspace name we want to connect to
Set-PBIGroup -authToken $authToken -name "Demos - Start Small Grow Big" -Verbose

# And for last we just pass the source and target dataset name or id
Set-PBIReportsDataset -authToken $authToken -sourceDataSetName "VanArsdel" -targetdatasetName "VanArsdel.AS" -Verbose

Voilá! With 4 lines of code, you can connect to your workspace, and change all the reports related to your source dataset to a new one. In the end, you can just check the related content of the old dataset and it should look like the following:

Empty, exactly as we wanted. Now just go ahead and delete it!

I hope it saves you some time. I know it has saved us quite a lot.

Take care!

Joana Barbosa

BI Developer @ Devscope, knocking data out using BI! Mostly using Microsoft Business Intelligence Stack like PowerBI and AzureAS.

Subscribe to Binary Lies

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!