Create a New Report In Embed View

Power BI embedding is a Platform-as-a-service (PaaS) provided by Microsoft Azure via which an independent service vendors (ISVs) can embed a visual, report or dashboard into an application. This ensures the secure a way of sharing a Power BI report without the consumer owning a Power BI account. However, when embedding the user just have a viewing access to the reports. What if the consumer can suggest some changes or want to make a new report then we cannot just say NO to them. So to overcome this, Microsoft Power BI provides us with an API to create a new report and this can be implemented quite easily.

 

Embed Token – Reports GenerateTokenForCreateInGroup

To create a new report we will be using Power BI API – GenerateTokenForCreateInGroup. This API generates an embed token to allow report creation on the specified workspace based on the specified dataset.

 

Requested Parameters

 

Name Type Description
groupid String The workspace Id

 

Request body

 

Name Type Description
accessLevel TokenAccessLevel Required access level for embedToken generation. For this use case it will be Create.
allowSaveAs Boolean Indicates an embedded report can be saved as a new report. Default value is ‘false’. Only applies when generating EmbedToken for report embedding.
datasetid String Dataset Id for report creation
Identities Effective Identity [] List of identities to use for RLS

 

This API will then return the embed token.

 

New Report Embed Token Generation

Server-Side Code

// Generate an embed token to create

var generateTokenRequestParameters = new GenerateTokenRequest(

TokenAccessLevel.Create,

“enter your datasetid”,

allowSaveAs: true

);

 

var tokenResponse = client.Reports.GenerateTokenForCreateInGroup(“enter your workspaceid”, generateTokenRequestParameters);

 

// Populate embed variables (to be passed client-side)

embedToken = tokenResponse.Token;

embedUrl = “https://app.powerbi.com/reportEmbed?groupId=” + “enter your workspaceid”;

datasetId = “enter your workspaceid”;

 

Note: RLS is not supported for this API. Hence, no effective identity have been defined in GenerateTokenRequest.

 

Client-Side Code

// Read embed token

var embedToken = “<% = this.embedToken %>”;

 

// Read embed URL

var embedUrl = “<% = this.embedUrl %>”;

 

// Read dataset Id

var datasetId = “<% = this.datasetId %>”;

 

 

// Get models (models contains enums)

var models = window[‘powerbi-client’].models;

 

// Embed configuration is used to describe what and how to embed

// This object is used when calling powerbi.embed

// It can also includes settings and options such as filters

var embedCreateConfiguration = {

type: ‘report’,

tokenType: models.TokenType.Embed,

accessToken: embedToken,

embedUrl: embedUrl,

datasetId: datasetId,

};

 

// Embed the report within the div element

var report = powerbi.createReport(embedDiv, embedCreateConfiguration);

 

var saveAsParameters = {

name: “newReport”

};

 

// SaveAs report

report.saveAs(saveAsParameters);

 

Addend Analytics is a Microsoft Power BI-partner based in Mumbai,India. Apart from being authorized for Power BI implementation, Addend has successfully executed Power BI projects for 100+ clients across sectors like financial services, banking, insurance, retail, sales, manufacturing, real estate, logistics, and healthcare in countries like the US, Europe, Australia, and India. Companies partnering with us save their valuable time and efforts of searching and managing resources while saving hugely on the development costs and hence, most small and medium enterprises in North America prefer Addend to their Power BI implementation partner. Get a free consultation now by emailing us at [email protected]

Pragya Verma
Data Analyst
Addend Analytics