Power Platform Dev Blog

Low code, but also pro code. sometimes. Always automated though

How to dynamically set a Power BI Report URL on Power Pages

I’ve recently had to work with an embedded Power BI report on Power Pages (previously Power Portals), this is a report that has a few different sections that needs to be displayed depending on the page we’re in. Nothing too complicated.

What I did want to find out was how could I easily configure the Power BI Report in a dynamic way. This is for a couple of reasons, first, this application will eventually be deployed to a different environment, I don’t want to have to manually change URLs everywhere I’ve used the Power BI report. Even if I use a CICD pipeline I still have to add a few tasks to search for the URL string everywhere and replace it with the destination environment URL.

Which leads me to the second reason, I’ve started using the Power Platform CLI for Power Pages deployments and I want to use a deployment profile to manage the different settings and configurations between environments.

The solution? A mix of content snippets and a few well-placed liquid tags.

Configuring the Content Snippet

This is a simple one. Our end result needs to be a Power BI liquid tag, something that looks like this:

{% powerbi authentication_type:"powerbiembedded" path:https://app.powerbi.com/groups/00000000-1234-5678-0000-000000000001/reports/00000000-0000-9876-5432-000000000002/ReportSectionf000d000f0000d0000f0 %}

So we need to store the changing part or the URL on a content snippet. To do this just go into the content snippets and create a new one. Save it as Text and store the URL up to the ReportSection part. It should look like this:

Build URL using Liquid

Liquid can be a pain sometimes, especially if you can’t find the tags to do what you need to do.

The one we’re going to need to build our Report URL is the capture. This tag captures the content of its block and stores it in a variable.

So, for our scenario we’ll just capture the content snippet created above and any other Report Sections we want to display within that page, and store it in a variable called pbi_path. Then we’ll use that variable as the path for our Power BI Report.

This should look something like this:

<div>     {% capture pbi_path %}{{ snippets["Power BI Report URL"] }}ReportSectionf000d000f0000d0000f0 {% endcapture %}
{% powerbi authentication_type:"powerbiembedded" path:pbi_path %}
</div>

That’s it. If you have any other Power BI reports just create another content snippet to ensure you have a single place where you can update its URL.

What about deploying to other environments?

Right, we now have a single place where we store our Power BI Report URL, but do I still have to go into my destination environment and update the content snippet every time I do a release? Nope!

If you are using the Power Platform CLI you can (and should!) take advantage of the deployment profiles when deploying your Power Pages application between multiple environments.

You can find more detail on deployment profiles here, but to keep it simple, on your VS Code project create a new folder called “deployment-profiles” and within it create two yaml files, one per environment, called “dev.deployment.yml” and “prod.deployment.yml”.

Within these we’ll define the records that we want to change per environment, in our case this is our “Power BI Report URL” content snippet. So open the dev.deployment.yml file and add the following:

adx_contentsnippet:
    - adx_contentsnippetid: 11111111-2222-3333-4444-555555555555 # Power BI Report
      adx_name: Power BI Report URL
      adx_value:  https://app.powerbi.com/groups/00000000-1234-5678-0000-000000000001/reports/00000000-0000-9876-5432-000000000002/

Note that you have to find your own adx_contentsnippetid that corresponds to the Power BI Report URL.

Then open your prod.deployment.yml and add the same thing but change the value to be the URL of the Production Power BI Report.

adx_contentsnippet:
    - adx_contentsnippetid: 11111111-2222-3333-4444-555555555555 # Power BI Report
      adx_name: Power BI Report URL
      adx_value:  https://app.powerbi.com/groups/11111111-2468-0000-0000-000000000001/reports/22222222-0000-9876-0000-123000321000/

That’s it! Just use the upload command while referencing the correct environment and you’re done!

pac paportal upload --path "C:\portals\starter-portal" --deploymentProfile prod