Skip to content

Create and Edit Report in Embed View

Amit Shuster edited this page Jan 21, 2021 · 3 revisions

Power BI Embedded reports can now be created from a dataset in your own application.

Embed Token

Relevant access token needed to create new report.

Token should have the following scopes: "Dataset.Read Workspace.Report.Create".

Find full article in Microsoft Docs

JavaScript to create a new blank report

var embedCreateConfiguration = {
    accessToken: 'eyJ0eXAiO...Qron7qYpY9MI',
    embedUrl: 'https://embedded.powerbi.com/ReportEmbed',
    datasetId: '5dac7a4a-4452-46b3-99f6-a25915e0fe55',
};

// Grab the reference to the div HTML element that will host the report
var reportContainer = $('#reportContainer')[0];

// Create report
var report = powerbi.createReport(reportContainer, embedCreateConfiguration);

Save new reports

The report will not actually be created until you call the save as operation. This can be done from file menu or from JavaScript.

var saveAsParameters = {
    name: "newReport"
};

// SaveAs report
report.saveAs(saveAsParameters);

Important

A new report is created only after save as is called. After you save, the canvas will still show the dataset in edit mode and not the report. You will need to reload the new report like you would any other report.

Load the new report

In order to interact with the new report you need to embed it in the same way the application embeds a regular report, meaning, a new token must be issued specifically for the new report and then call the embed method.

var embedConfiguration = {
    accessToken: 'eyJ0eXAiO...Qron7qYpY9MJ',
    embedUrl: 'https://embedded.powerbi.com/ReportEmbed',
    reportId: '5dac7a4a-4452-46b3-99f6-a25915e0fe54',
    viewMode: 'edit'
};

// Grab the reference to the div HTML element that will host the report
var reportContainer = $('#reportContainer')[0];

// Embed report
var report = powerbi.embed(reportContainer, embedConfiguration);

Automate save and load of a new report using the "saved" event

Find full article in Microsoft Docs

Save report

call report.save to save user changes. Works if you

await report.save();

Check if the report is saved

Call report.isSaved to check if the report is saved. Using this method can help customers to avoid losing unsaved changes.

bool isSaved = await report.isSaved();
Clone this wiki locally