Forum Discussion
Power BI Api approach for dynamic report generation
- 4 years ago
Hi ms92ita,
Yes. You should create a dataset for each customer and then generate an embed token with the right DatasetID.
In addition, you should add the following to the config object:datasetBinding: { datasetId: "<DatasetId>" }See dynamic binding and bind datasets dynamically to a report
Hi ms92ita,
Yes. You should create a dataset for each customer and then generate an embed token with the right DatasetID.
In addition, you should add the following to the config object:
datasetBinding: {
datasetId: "<DatasetId>"
}
See dynamic binding and bind datasets dynamically to a report
- ms92ita4 years ago
Helper I
Hi,
I have done these steps:
1) create a copy of the dataset from a .pbix template (PostImportWithFileInGroup from c# API)2) update datasource settings of new dataset in order to point to the right database (UpdateDatasourcesInGroup from c# API): at the moment, the databases are in the same server so credentials are valid
3) generate a token for the report with both original and new dataset with this code:
var pbiReport = client.Reports.GetReport(groupid, reportid); EmbedToken embedToken; // Create list of dataset var datasetIds = new List<Guid>(); // Add dataset associated to the report datasetIds.Add(Guid.Parse(pbiReport.DatasetId)); // Append additional dataset to the list to achieve dynamic binding later datasetIds.Add(Guid.Parse(newreportid)); // Get Embed token multiple resources var tokenRequest = new GenerateTokenRequestV2( reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(reportid) }, datasets: datasetIds.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(), targetWorkspaces: groupid != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { new GenerateTokenRequestV2TargetWorkspace(groupid) } : null ); // Generate Embed token embedToken = client.EmbedToken.GenerateToken(tokenRequest);4) create report view from JS with the correct report id
const config = { type: 'report', tokenType: models.TokenType.Embed, accessToken: accessToken, embedUrl: embedUrl, id: embedReportId, datasetBinding: { datasetId: "newdatasetid", // The dataset id that you want the report to use }, datasetId: "newdatasetid", permissions: models.Permissions.All, settings: { // Enable this setting to remove gray shoulders from embedded report // background: models.BackgroundType.Transparent, panes: { filters: { expanded: false, visible: true }, pageNavigation: { visible: true } } } }; // Embed the dashboard and display it within the div container. const report = powerbi.embed(embedContainer, config);
The report is blank. Also, filter visuals are empty
From console, I have seen that a call has 403 result
UPDATE:
i have refreshed credentials from the gateway with UpdateDatasource and not it seems to work fine. I will try later with multiple binding but probably the circle has been closed- SpartaBI4 years ago
Community Champion
ms92ita great, so please accept all the messages that helped you as solutions, and will appreciate your kudos on them
- ms92ita4 years ago
Helper I
Last question related to the initial visual of a report: in some pages, I have a dropdown filter that that acts on the graphs and is populated by a table.
I have noticed that in first stage the dropdown views the "default" value even if I am using an another dataset. Dropdown values after loading are correct. How can I avoid default value or overwrite it in the first instance (for example empty value)?