Power BI Embedded Setup

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Power BI Embedded Setup: A Comprehensive Guide

Introduction: Bridging Data and Application

In the modern landscape of software development, the ability to present data in an actionable, visual format is no longer a luxury—it is a baseline requirement. Most organizations rely on Power BI to manage their business intelligence, but there is often a disconnect between the data living in the Power BI portal and the custom applications that users interact with daily. Power BI Embedded is the bridge that solves this problem. It allows developers to integrate fully interactive reports, dashboards, and tiles directly into their own web applications or portals.

By using Power BI Embedded, you stop forcing your users to leave your application to view analytics. Instead, you provide a unified experience where the software they use to perform their tasks also provides the insights they need to make decisions. This integration increases user engagement, reduces context-switching, and allows you to leverage the sophisticated visualization engine of Microsoft without building your own charting libraries from scratch. This lesson will guide you through the architectural requirements, the setup process, and the best practices for implementing this solution effectively.

Not read yet

Understanding the Architecture

Power BI Embedded is not just a single tool; it is a service that relies on the interaction between your application, the Power BI service, and Microsoft Entra ID (formerly Azure Active Directory). To implement this, you must understand the "App Owns Data" model, which is the most common pattern for software-as-a-service (SaaS) providers. In this model, your application holds the credentials and manages the access for your users.

When a user visits your application, your backend server requests an access token from Microsoft Entra ID. This token acts as a passport, proving that your application has the right to view specific reports. Your backend then exchanges this token for an "Embed Token," which is specific to the report or dashboard you want to display. The client-side application then uses this Embed Token to render the Power BI content within an iframe. This process ensures that your users do not need their own Power BI Pro licenses to view reports, provided you have the appropriate capacity in Azure.

Callout: Embedded vs. Power BI Service Many developers confuse "embedding" with simply sharing a link. The Power BI Service is a portal for analysts to build and view reports. Power BI Embedded is a developer-centric service that strips away the portal UI and provides a programmatic interface to render the visualization layer inside your own application’s DOM, allowing for custom styling and deep integration.

Not read yet

Prerequisites for Implementation

Before writing any code, you need to ensure your environment is configured correctly. You cannot simply point to a report and have it appear. The following components must be in place:

  • Azure Subscription: You need an active Azure subscription to create the "Power BI Embedded" resource (the A-SKU or P-SKU capacity).
  • Power BI Pro or Premium Per User (PPU) License: The developer who creates and publishes the report to a workspace must have a license.
  • Power BI Workspace: This is where your reports will live. It is best practice to keep these separate from personal workspaces.
  • Microsoft Entra ID Application: You must register an application in the Azure portal to handle the authentication flow.
  • Service Principal: This is the identity that your application will use to authenticate with Power BI.

Warning: Licensing Considerations If you are using the "App Owns Data" model, ensure your capacity is sized correctly. If you use a shared capacity, you are restricted by the limitations of the Power BI service limits. For production applications, always provision a dedicated capacity (A-SKU) in Azure to ensure predictable performance for your end users.

Not read yet

Step-by-Step Setup Process

Step 1: Registering the Application in Entra ID

  1. Navigate to the Azure Portal and search for "App registrations."
  2. Click "New registration" and give your app a descriptive name.
  3. Under "Supported account types," choose "Accounts in this organizational directory only" if you are building an internal tool, or "Accounts in any organizational directory" for multi-tenant apps.
  4. Once created, note the Application (Client) ID and the Directory (Tenant) ID. You will need these for your configuration file.
  5. Navigate to "Certificates & secrets" and create a "New client secret." Store the value securely, as you will not be able to see it again.

Step 2: Configuring the Power BI Workspace

You need to grant your application access to the workspace where your reports reside.

  1. Open the Power BI Service (app.powerbi.com).
  2. Navigate to the workspace where you have published your reports.
  3. Click on "Manage access."
  4. Add your registered Application (Service Principal) as a member or contributor.
  5. Ensure that the Service Principal has the necessary rights to view the reports within that workspace.

Step 3: Setting Up the Capacity

Without capacity, your embedded content will not render.

  1. In the Azure Portal, create a new "Power BI Embedded" resource.
  2. Choose your subscription, resource group, and a name for the capacity.
  3. Select the SKU that fits your budget and performance requirements (e.g., A1 is the entry level).
  4. Once the resource is created, assign your workspace to this capacity in the Power BI Service settings under "Workspace settings" -> "Premium."

Not read yet

Integrating the Backend: Generating the Embed Token

The core of the logic happens on your server. You need to use the Power BI REST API to request the token. Below is a conceptual example using Node.js and the powerbi-client library, but the logic remains consistent across languages like C# or Python.

const { PowerBIClient } = require('powerbi-client');
const { ClientSecretCredential } = require('@azure/identity');

async function getEmbedToken(reportId, workspaceId) {
    const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
    const client = new PowerBIClient(credential);

    // Request the token from the Power BI API
    const tokenResponse = await client.reports.generateTokenInGroup(
        workspaceId,
        reportId,
        {
            accessLevel: "View"
        }
    );

    return tokenResponse.token;
}

Explaining the Code

The ClientSecretCredential uses the credentials you created in the Entra ID step to authenticate your server with Azure. The generateTokenInGroup method is the critical call; it asks Power BI for a temporary, scoped token that grants permission to view a specific report. This token is what you will pass to the frontend.

Tip: Token Expiration Embed tokens have a limited lifespan (usually one hour). Your backend should be architected to refresh this token periodically. If a user leaves the page open for a long time, your frontend should detect the token expiry and request a new one from the backend to avoid the report going blank.

Not read yet

Integrating the Frontend: Rendering the Report

Once your backend has provided an Embed Token, the client-side code takes over. You will use the powerbi-client JavaScript library to inject the report into a container.

<div id="report-container" style="height: 600px; width: 100%;"></div>

<script src="powerbi.js"></script>
<script>
    const models = window['powerbi-client'].models;
    const reportContainer = document.getElementById('report-container');

    const config = {
        type: 'report',
        tokenType: models.TokenType.Embed,
        accessToken: 'YOUR_GENERATED_TOKEN',
        embedUrl: 'YOUR_REPORT_EMBED_URL',
        id: 'YOUR_REPORT_ID',
        settings: {
            filterPaneEnabled: false,
            navContentPaneEnabled: true
        }
    };

    const report = powerbi.embed(reportContainer, config);
</script>

Key Parameters Explained

  • embedUrl: This is the unique URL provided by the Power BI API when you query for the report metadata.
  • settings: This object allows you to control the user interface. For example, setting filterPaneEnabled to false creates a cleaner, more application-like look, while navContentPaneEnabled allows users to switch between pages in the report.
  • powerbi.embed: This initializes the iframe and handles all the communication between your app and the Power BI backend.

Not read yet

Security and Best Practices

Security is paramount when dealing with embedded analytics. You are essentially exposing internal data to a web browser, so you must ensure that only authorized users can access the report.

Row-Level Security (RLS)

The most powerful security feature in Power BI is Row-Level Security. RLS allows you to restrict the data a user can see based on their identity. If you have a multi-tenant application, you don't want Company A seeing Company B's data. You can pass an identity object when generating the embed token.

const tokenRequest = {
    accessLevel: "View",
    identities: [{
        username: "[email protected]",
        roles: ["Manager"],
        datasets: ["YOUR_DATASET_ID"]
    }]
};

By defining roles in Power BI Desktop (e.g., a "Manager" role that filters by CompanyID), and then passing the user's specific context in the token request, Power BI automatically filters the data for that user. This ensures that the data is secure at the database level, not just the visual layer.

Performance Optimization

Embedding reports can be resource-intensive. To keep your application snappy:

  1. Use Bookmarks: Instead of loading five different reports, create one report with multiple bookmarks and use the API to switch between them.
  2. Optimize Data Models: A report is only as fast as its underlying DAX queries. Ensure your models use Star Schema and limit the number of visuals on a single page.
  3. Lazy Loading: Do not initialize the report until the user actually navigates to the tab containing the data.

Callout: The Importance of the Star Schema Performance issues in embedded reports are rarely caused by the embedding process itself. They are almost always caused by inefficient DAX or a "flat" data model. Always normalize your data into a Star Schema (fact and dimension tables) before publishing to Power BI to ensure the embedded reports remain responsive.

Not read yet

Common Pitfalls and Troubleshooting

1. The "403 Forbidden" Error

This is the most common error when starting out. It usually means the Service Principal has not been added to the workspace, or the workspace is not assigned to a capacity. Double-check your workspace access settings and ensure your Azure subscription has an active Power BI Embedded resource.

2. Token Refresh Failures

If your reports stop working after an hour, you have not implemented a token refresh strategy. Use the report.on('tokenExpired', ...) event listener in your JavaScript to trigger a new request to your backend.

3. Cross-Origin Resource Sharing (CORS) Issues

If you are developing locally, ensure your localhost address is included in the allowed origins within your Azure App Registration settings. Without this, the browser will block the connection to the Power BI service.

4. Browser Privacy Settings

Some browsers (like Safari) have strict "Intelligent Tracking Prevention" (ITP) policies that block third-party cookies. Power BI Embedded relies on these cookies for authentication. If you notice the report works in Chrome/Edge but not Safari, you may need to implement a "Storage Access API" wrapper or ensure your application is served over a secure HTTPS connection.

Not read yet

Comparison Table: Embedding Models

Feature App Owns Data User Owns Data
Authentication Service Principal / App User Login (OAuth)
User License Not required for end-users Pro/PPU required for all users
Best For SaaS apps, public portals Internal corporate dashboards
Complexity Higher (requires backend logic) Lower (uses standard auth)
Security Managed by App (RLS) Managed by Power BI

Advanced Integration: Interacting with the Report

Power BI Embedded is not just a static image. You can interact with the report using the powerbi-client API. This allows you to create a "two-way" conversation between your application and the report.

Changing Filters Programmatically

You can react to user actions in your own application by applying filters to the report.

const filter = {
    $schema: "http://powerbi.com/product/schema#basic",
    target: {
        table: "Sales",
        column: "Region"
    },
    operator: "In",
    values: ["North America"]
};

report.updateFilters(models.FilterOperations.Replace, [filter]);

This allows you to build custom search bars or dropdowns in your HTML that control the data displayed in the Power BI report, creating a truly unified interface.

Handling Events

You can also listen to events coming from the report. For example, if a user clicks on a chart, your application can capture that event and update other parts of your UI.

report.on('dataSelected', (event) => {
    const data = event.detail.dataPoints;
    console.log("User selected data:", data);
});

This level of interactivity is what separates a basic "iframe" integration from a high-quality, professional data application.

Not read yet

Best Practices for Production

  1. Use Environment Variables: Never hardcode your Client ID, Tenant ID, or Client Secret in your source code. Use environment variables or a secret manager like Azure Key Vault.
  2. Implement Robust Logging: Wrap your token generation requests in try-catch blocks and log the errors to a service like Application Insights. This makes debugging much faster when a user reports a blank screen.
  3. Mobile Responsiveness: Use the layoutType property in your embed configuration to switch between desktop and mobile layouts. This ensures your analytics are usable on phones and tablets.
  4. Graceful Degradation: If the report fails to load, provide a user-friendly message rather than a broken UI. Check the error event on the report object to provide specific feedback.

Key Takeaways

  • Architectural Foundation: Power BI Embedded requires a clear separation between your backend (which handles secure authentication with Entra ID) and your frontend (which renders the visual components).
  • Capacity Management: Always provision a dedicated capacity (A-SKU) for production environments to avoid the limitations and unpredictability of shared resources.
  • Security First: Utilize Row-Level Security (RLS) to ensure that users only see the data they are authorized to access, preventing data leakage in multi-tenant environments.
  • Programmatic Control: Use the JavaScript SDK to move beyond static reports. By utilizing filters, event listeners, and bookmarks, you can create a seamless experience where your app and the report interact dynamically.
  • Maintenance: Embed tokens are temporary. A successful implementation must include a token refresh strategy to ensure long-running sessions remain active without user intervention.
  • Performance: Treat embedded reports like any other heavy client-side asset. Optimize your DAX and data models, and use lazy loading to keep your application’s initial load time fast.

By following these guidelines, you can move away from siloed reporting and toward a data-driven application architecture that provides genuine value to your users. Power BI Embedded is a powerful tool, and when implemented with attention to detail, it can transform how your users interact with their data, leading to better insights and more informed decision-making across your organization.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.