Setting up a Power BI deployment pipeline with environment-specific data sources
Tags: powerbi, dataverse
Published: 2022-05-25 04:50:06

#Introduction

Power BI Deployment Pipelines allow you to implement Application Lifecycle Management (ALM) for your Power BI Service workspaces. Today I'll show you how to use one-click deployment to elevate changes from dev through to production.

#Prerequisites
- You must have Power BI Premium license to use Deployment Pipelines. You should be able to get a trial for 60 days.
- You'll also need Power BI Desktop installed.

#Creating Premium Workspaces
The first thing to do is to create premium workspaces - you'll need one for each environment.

At app.powerbi.com, go to Workspaces / Create Workspaces

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yrc9ygtbud880phkgt7x.png)
 
Make sure you pick Premium per user as license mode.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y2hjrhngubuuegol80p6.png)

In our case, we'll create two workspaces - Dev and Test.

#Creating pipeline

Once the workspaces are created, go and create a pipeline.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgbd3kmfbwp7wd5x3z6t.png)

Assign your dev workspaces to the Development stage

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r235mj1oe2l1hoqjcrul.png)
 
#Your Pipeline View

This is your pipeline view - you have three stages - Development, Test and Production. Each stage is attributed to one workspace. In this example, we'll demonstrate going from Dev to Test but going to Production should be exactly the same process. 

The last thing to do in this view is to assign the Test workspace to the Test stage

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tedz2fksxhkllxedvnw.png)

#Creating a report in PowerBI Desktop

We want to connect a report in PowerBI Desktop to demonstrate how the pipelines work. A common difference between each of your power bi environments is going to be the data source. Your dev environment should connect to the dev database, your test environment to test database and so on.

How to use Power BI Desktop is outside the scope of this article but the quickest way is to open up the application and select Get Data

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxyyxf2rfl1ma3nphwr5.png)
 
Any data source is fine but for my case, I'd like to create visualisations for a Power App so I'm going to select Dataverse as the data source. It'll ask you to sign in using your Azure AD account and select the Power App environment.

In this report, I've similarly grabbed all the data in the "accounts" table.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rx2lqz4bg2kjy6kv761t.png)

#Adding a parameter

I want to add a parameter for the data source because that is going to be customised for each stage. If you go to Transform data, on the ribbon, there should be a New Parameter button

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jl0byzsfwms4cppzbdt1.png)

Create the parameter by giving it a name. 

Select "List of Values" under Suggested Values and put in the URLs of all the environments that you would like to deploy to and select the dev URL as the environment you'd like to deploy to.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wekpl15196p3qbrn5lg0.png)
 
#Using the parameter in the Data Model

Instead of the report pointing to the Dev as the data source, we want it to point to the current parameter value. Therefore, for each table under the Source applied step, change the URL to be #"DataSource". 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttsurmiwbvywiavg0iqa.png)
 
#Creating and publishing a report

We'll now create a report to demonstrate the data being in different environments. For this example, I have created a simple report that simply counts the number of accounts in different statuses. These should different which will allow me to verify it's getting data from different environments.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwcjqzlv3njmlnrn0tta.png)

Once you have created your report, click the Publish button on the ribbon and select the Dev workspace.

#Deployed to Dev

You've successfully published your report onto the Dev Workspace inside your Power BI Service. Go to the deployment pipeline and check that inside the dev environment, you should see 1 data set and 1 report deployed. If you go to the report, you should be able to see the report in Power BI Service.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63cbpkos9davg6gp4shj.png)
 
#Pointing the parameter variable to Test

We've successfully deployed to Dev, we now want to deploy to Test - we want to use the same artefacts but we want to change the data source so it's pointing to the Test Database.

The first thing we should do is Deploy to Test.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xkpg707b9h23fzgynw6p.png)

Once the report is deployed to Test, we should set up a parameter rule. Click on the lightning settings icon for Test and select the Dataset you've just deployed.
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnq92w20fzxih0l69q02.png)
 
Set up a parameter rule and point it to Test URL

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4zgjohq8mmn00q3lp8v.png)
 
Deploy again. Once completed, if you go to the Test workspace open the report, it should show data in Test.

#Extra tips

##Verifying the parameters

If you want to double check whether the parameters have been set correctly for each workspace, go to the Dataset settings and you can check under Parameters what the value is.

##Setting the connection 

Also, if you're having connection issues, you can also go to the Dataset settings, under Data source credentials, either log in or check "Report viewers can only access this data source with their own Power BI identifies". I generally tick this to ensure only the data the user has access to is in the report.
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9onia7b8wmy8tva7pnn1.png)