Power BI Embed Component

A generic Power BI report embedding component for displaying Power BI reports and dashboards within web applications.

Usage

<!-- Basic usage -->
<qds-powerbi-embed 
  workspace-id="f089354e-8366-4e18-aea3-4cb4a3a50b48"
  report-id="5b218778-e7a5-4d73-8187-f10824047715">
</qds-powerbi-embed>

<!-- With navigation and filter panes -->
<qds-powerbi-embed 
  workspace-id="f089354e-8366-4e18-aea3-4cb4a3a50b48"
  report-id="5b218778-e7a5-4d73-8187-f10824047715"
  show-filter-pane="true"
  show-nav-pane="true"
  embed-mode="view">
</qds-powerbi-embed>

<!-- Specific page with custom size -->
<qds-powerbi-embed 
  workspace-id="f089354e-8366-4e18-aea3-4cb4a3a50b48"
  report-id="5b218778-e7a5-4d73-8187-f10824047715"
  page-name="RevenueAnalysis"
  style="height: 800px;">
</qds-powerbi-embed>

Attributes

Attribute Type Default Description
workspace-id string - Required. Power BI workspace ID
report-id string - Required. Power BI report ID
page-name string - Specific page to display (optional)
embed-mode string "view" Embed mode: view, edit, or create
show-filter-pane boolean false Show/hide the filter pane
show-nav-pane boolean false Show/hide the navigation pane
filters string - JSON string of pre-applied filters
auth-token string - Power BI access token (for authenticated embeds)
embed-url string - Custom embed URL (optional, auto-generated if not provided)

CSS Custom Properties

The component uses QDS theme variables and can be customized with CSS:

qds-powerbi-embed {
  --powerbi-embed-background: var(--theme-background-primary);
  --powerbi-embed-border-color: var(--theme-border-primary);
  --powerbi-embed-accent-color: var(--theme-accent-primary);
  --powerbi-embed-text-color: var(--theme-text-primary);
  --qds-font-family: var(--theme-font-family);
}

CSS Parts

Style internal elements using CSS parts:

qds-powerbi-embed::part(container) {
  border-radius: 12px;
}

qds-powerbi-embed::part(iframe) {
  border: 2px solid var(--theme-border-strong);
}

qds-powerbi-embed::part(loading) {
  background: var(--theme-background-secondary);
}

qds-powerbi-embed::part(error) {
  background: var(--theme-background-error-subtle);
}

Events

The component fires custom events for integration:

const embed = document.querySelector('qds-powerbi-embed');

// Report successfully loaded
embed.addEventListener('loaded', (event) => {
  console.log('Report loaded:', event.detail);
  // { reportId: "5b218778...", workspaceId: "f089354e..." }
});

// Error occurred during loading
embed.addEventListener('error', (event) => {
  console.log('Error:', event.detail);
  // { error: "Failed to load report", reportId: "5b218778..." }
});

// Data selected in the report (requires Power BI JS API integration)
embed.addEventListener('dataSelected', (event) => {
  console.log('Data selected:', event.detail);
  // { selection: {...}, reportId: "5b218778..." }
});

// Export requested
embed.addEventListener('export-requested', (event) => {
  console.log('Export requested:', event.detail);
  // { format: "pdf", reportId: "5b218778..." }
});

Methods

refresh()

Refreshes the embedded report:

const embed = document.querySelector('qds-powerbi-embed');
embed.refresh();

exportToPDF()

Triggers a PDF export request:

const embed = document.querySelector('qds-powerbi-embed');
embed.exportToPDF();

Authentication

For production use, you’ll need to provide authentication tokens:

<qds-powerbi-embed 
  workspace-id="your-workspace-id"
  report-id="your-report-id"
  auth-token="your-power-bi-access-token">
</qds-powerbi-embed>

Note: The current implementation uses iframe embedding which requires proper Power BI configuration and authentication. For production use, consider implementing the Power BI JavaScript API for enhanced functionality.

Responsive Design

The component is responsive by default:

qds-powerbi-embed {
  height: 100vh; /* Full viewport height */
}

@media (max-width: 768px) {
  qds-powerbi-embed {
    height: 300px; /* Smaller on mobile */
  }
}

Error Handling

The component gracefully handles various error states:

Error messages are displayed in the component with appropriate styling.

Security Considerations

Browser Support

Requires modern browser support for Web Components and Shadow DOM.

Future Enhancements

Planned features for future versions: