Back to Blog

๐Ÿง  Dynamic Power BI Embedding in Power Pages Using request.params

Cameron Shields
Power Platforms
๐Ÿง  Dynamic Power BI Embedding in Power Pages Using request.params

๐Ÿงฐ Introduction

Microsoft Power Pages provides a robust platform for building secure, low-code websites. Integrating Power BI reports into these pages enhances data visualization and user engagement. By utilizing request.params, developers can dynamically load different reports based on URL parameters, offering a tailored experience without the need for multiple pages.

๐Ÿ”ง Understanding request.params in Power Pages

In Power Pages, request.params is a Liquid object that captures query string parameters from the URL. For example, if a user accesses:

https://cameronshields.co.uk/report?reportId=12345

You can retrieve the reportId using:

{% assign report_id = request.params.reportId %}

This value can then be used to dynamically construct the embed URL for the Power BI report.

๐Ÿ“„ Embedding Power BI Reports Dynamically

๐Ÿ”น Retrieve the reportId Parameter

{% assign report_id = request.params.reportId %}

๐Ÿ”น Construct the Embed URL Assuming you have a base URL for embedding reports, append the reportId: {% assign embed_url = "https://app.powerbi.com/reportEmbed?reportId=" | append: report_id %}

๐Ÿ”น Embed the Report in an IFrame "<iframe width="100%" height="600" src="{{ embed_url }}" frameborder="0" allowFullScreen="true"></iframe>"

This setup allows the same page to display different reports based on the reportId provided in the URL.

โš ๏ธ Handling Caching Issues

Be aware that Power Pages may cache header and footer content, which can affect dynamic content rendering. To ensure that request.params reflects the current URL parameters, disable output caching for headers and footers:

  1. Navigate to Site Settings in your Power Pages admin centre.
  2. Set the following settings to false:
  • Header/OutputCache/Enabled
  • Footer/OutputCache/Enabled This ensures that dynamic parameters are correctly processed on each page load.

๐Ÿ” Security Considerations

When embedding Power BI reports, ensure the following:

  • Authentication: Ensure that users are authenticated appropriately to access the reports.
  • Row-Level Security (RLS): Implement RLS in Power BI to restrict data access based on user roles.
  • Validate Parameters: Always validate and sanitise URL parameters to prevent injection attacks or unauthorised access.

๐Ÿงช Testing the Implementation

To test dynamic report loading, access your Power Pages site with different reportId values in the URL:

https://cameronshields.co.uk/report?reportId=abc123

https://cameronshields.co.uk/report?reportId=def456

Verify that the embedded report changes accordingly.

Ensure that users without proper permissions cannot access restricted reports.