Power BI Embed Proof of Concept
Explore four key embedding scenarios with the Power BI JavaScript SDK
Create New Report
Create a new Power BI report from scratch using an existing dataset/data model.
Key Features:
Connect to existing datasets
Use report authoring tools
Add visualizations
Save to workspace
Edit Existing Report
Load and edit an existing Power BI report with full editing capabilities.
Key Features:
Load existing reports
Modify visualizations
Change data bindings
Save changes
Semantic Models
View and manage semantic models (datasets) in your workspace.
Key Features:
Browse semantic models
Refresh data
View model details
Open in Power BI
Paginated Reports
Create and edit paginated reports (RDL) with export capabilities.
Key Features:
View paginated reports
Set parameters
Export to PDF/Excel
Print-ready layouts
How the System Works
This demo uses a secure, enterprise-ready architecture for embedding Power BI reports. The system follows a three-step process: authentication, token generation, and embedding with API controls.
The backend generates embed tokens with specific permissions and parameters based on the embedding scenario.
Token Generation Flow:
- 1. Client Request
Frontend requests embed config via API route (e.g., /api/reports/[id]/embed)
- 2. Access Token
Backend obtains Azure AD access token using service principal credentials
- 3. Embed Token
Backend calls Power BI REST API GenerateToken endpoint with report/dataset IDs and permissions
- 4. Return Config
Backend returns embed URL, token, and settings to frontend
Permission Levels:
Token Parameters:
{
reports: [{ id: "report-id" }],
datasets: [{ id: "dataset-id" }],
preferredEmbedTokenVersion: "V2",
accessLevel: "view" | "edit" | "create"
}Once the embed token is received, the frontend uses the Power BI JavaScript SDK to embed the report and exposes UI controls for interacting with the embedded content.
Embedding Process:
- Power BI SDK Initialization
Initialize powerbi.embed() with embed URL, access token, and configuration settings
- Report Rendering
SDK creates iframe and loads Power BI report in specified container element
- Event Listeners
Subscribe to events: 'loaded', 'error', 'saved', 'dataSelected', 'pageChanged'
- UI Controls
Expose buttons and controls that call SDK methods (save, refresh, print, export)
Available API Controls:
const report = powerbi.embed(container, {
type: 'report',
id: reportId,
embedUrl: embedUrl,
accessToken: accessToken,
permissions: Permissions.All,
viewMode: ViewMode.Edit
});
// Expose UI controls
report.on('loaded', () => {
// Enable save button
saveButton.onclick = () => report.save();
});Row-Level Security (RLS) enables data filtering at the dataset level based on user identity, ensuring users only see data they're authorized to access. This is critical for multi-tenant scenarios and data governance.
How RLS Works:
- 1. Dataset RLS Configuration
RLS rules are defined in Power BI dataset using DAX expressions (e.g., [Region] = USERNAME())
- 2. Identity Resolution
Frontend passes user identity (username/roles) via HTTP headers (x-pbi-username, x-pbi-roles)
- 3. Token Generation
Backend includes identities array in GenerateToken request to Power BI REST API
- 4. Data Filtering
Power BI applies RLS rules when rendering report, filtering data based on embedded identity
RLS Components:
Identity Format:
{
identities: [{
username: "[email protected]",
roles: ["Sales", "Manager"],
datasets: ["dataset-id"]
}]
}Implementation Example:
// Frontend: Pass identity in request headers
const response = await fetch('/api/paginated-reports/[id]/embed', {
headers: {
'x-pbi-username': '[email protected]',
'x-pbi-roles': 'Sales,Manager'
}
});
// Backend: Resolve identities from headers
const identities = resolvePaginatedIdentities(request);
// Returns: [{ username: '[email protected]', roles: ['Sales', 'Manager'] }]
// Backend: Include in token generation
const embedToken = await authService.generatePaginatedReportEmbedToken(
reportId,
workspaceId,
datasetId,
{ identities }
);
// Power BI: Applies RLS rules based on identity
// Dataset DAX: [Region] = USERNAME() OR USERROLE() = "Manager"Important Notes:
- RLS is dataset-level
RLS rules must be configured in the Power BI dataset, not the report
- Service Principal Context
When using service principal, identities must be explicitly passed in embed token - Power BI cannot infer user context
- Paginated Reports
RLS is especially important for paginated reports which query datasets directly via XMLA
- Testing RLS
Use Power BI Desktop to test RLS rules with View As before deploying to service
Technical Implementation
Backend Technologies:
Frontend Technologies:
Prerequisites:
• Azure AD application with Power BI permissions
• Power BI workspace with premium capacity or Pro license
• Sample datasets and reports in your workspace
• Environment variables configured in Vercel for API calls