DEV Community

Akshay Ram Vignesh
Akshay Ram Vignesh

Posted on • Originally published at on

How To Embed Microsoft Power BI Charts Into Your React Application

Embedding Microsoft Power BI charts into your React Application can be breeze with the right tools.

Note: This article assumes you have a fairly decent idea about Microsoft Power BI and few related terminologies.


Install powerbi-report-component using your favourite package manager.

npm i powerbi-report-component --save-dev


yarn add powerbi-report-component --dev

Basic usage,

import Report from "powerbi-report-component";


Now, for the those who stayed :)

Embedding a Power BI report into your React Application can be a pain for a beginner. Even though the Microsoft's documentation on the topic is pretty neat.

I'm just gonna tell you what's need from a React developer's perspective and not go into the details of implementation or architecture.

There are two approaches that you can take to embed your Power BI Report:

  1. User Owns Data
  2. App Owns Data

The main difference is:

User Owns Data sample is for Embedding for your organisation, the embedded reports readers can be Power BI Pro or free users in your organisation. Users have to log-in with their PBI account. Power BI Premium license is required. (i.e, Users who are part of your AD)

App Owns Data sample is for Embedding for your customers, the embedded report readers can be your own customers(say you're an ISV application provider). So no log-in. Power BI Embedded license is required.(i.e, Users outside your AD)


You have to choose who will be using your application that's gonna contain your embedded report i.e, Internal users(AD User) vs. External users(Non AD).

Now that you've decided on which approach you're gonna choose.

Hopefully, You have your report ready and are able to view it in

Now, navigate to your report under your workspaces your URL should look something like this:{workspace-id}/reports/{report-id}

for dashboards you might have something like this:{workspace-id}/dashboards/{dashboard-id}

To Embed your report you'll need the following:

  1. Report ID: from the URL
  2. Workspace ID: also, from the URL
  3. Token: AAD or Embed Token (For authetication))

Note: AAD token is used while taking the User Owns Data Approach and Embed token is used when taking App Owns Data Approach.

Embed Url: (Will consist of Report ID and Workspace ID)

There are mainly two ways you can proceed with embedding the report into your react application.

  1. Using an iframe
  2. Using Power BI JS API provided by Microsoft

Using an iframe is pretty straightforward but, this doesn't provide the flexibility that a React component would provide, like callbacks or event triggers.

You can use the generated URL to embed using iframe like this,


But, naturally as JS developers we tend to go with the more flexible JS API.

You can take a look at Microsoft's demo page

They have a very clear explanation and demo in Vanilla JS which uses their Javascript API.

You might be wondering, the demo is in Vanilla JS so if I have to make it a React Component and use it in my app.hmm, that might take a while 🤔

powerbi-report-component to the rescue! ✨

Check out the package.


import Report from "powerbi-report-component";

  embedType="report" // or "dashboard"
  tokenType="Embed" // or "Aad"
  accessToken="" // accessToken goes here
  embedUrl="" // embedUrl goes here
  embedId="" // Report or Dashboard ID goes here
  permissions="All" // or "View"

Currently supported features:

  1. Custom styling by passing style to your embedded report component.
  2. The component also lets you pass callbacks to trigger on events like:

Page Change

onPageChange={(data) =>
  console.log(`Page name :{data.newPage.displayName}`)


onLoad={(report) => {
      console.log('Report Loaded!'); = report;
// Read docs to know how to use the report object that is returned

Data Element Clicked

onSelectData={(data) =>
  console.log(`You clicked on chart: {data.visual.title}`)
  1. Use 'report' object returned to parent component for:


setFullscreen = () =>

Print Report

printReport = () =>

Change report mode, show/hide visual headers, filters(set, get, remove)

Change Mode

// mode can be "view" or "edit"

changeMode = mode =>

Show or Hide Visual Headers

toggleAllVisualHeaders = bool => {
  const newSettings = {
    visualSettings: {
      visualHeaders: [
          settings: {
            visible: bool,
    .then(function() {
      console.log(`Visual header was toggled to {bool}`)
    .catch(function(errors) {

Set Filters

//example filter object from Microsoft's demo page

    const filter = {
      $schema: "",
      target: {
        table: "Store",
        column: "Chain"
      operator: "In",
      values: ["Lindseys"]

    // using event handlers

    setFilter = (filter) =>[filter]).catch(function (errors) {

    // during load of report

    onLoad = (report) => {
      report.setFilters([filter]).catch(function (errors) {
      }); = report;

Get Filters

getFilter = () =>
    .then(function(filters) {
    .catch(function(errors) {

Remove Filters

removeFilters = () => {

More features coming soon! ⚡️

Links: Demo site, GitHub

I would love to hear your thoughts and feedback (also any request for new features at

Top comments (0)