How to bind multiple Power BI datasets to a single Power BI Report

0 votes

0

I have a user name logging into the Web Application.

I am using HTML, CSS, JavaScript and ASP.NET webform to run the Web Application with Power BI embedded reports.

I am trying to code to pass Server Name and Database name based on the user logged in to Power BI embedded config.

How to pass server name and database name to Power BI Embedded config?

Tried to test the application flow with Import Data Sets using following things, but the Power BI Report is not getting loaded in HTML div element. Its giving "Power BI Loading logo" in the embed div and then showing message as "Power BI content is not available"

Application Flow:

  1. Power BI workspace has One Report and Two Datasets

  2. Following is the Token generation code in .NET

            // Generate an embed token and populate embed variables
            using (var client = new PowerBIClient(new Uri(Configurations.ApiUrl), Authentication.GetTokenCredentials()))
            //using (var client = new PowerBIClient(new Uri(Configurations.ApiUrl), Authentication.m_tokenCredentials))
            {
                var report = client.Reports.GetReportInGroup(new Guid(Configurations.WorkspaceId), new Guid(ddlReport.SelectedValue));
                                                           
                var rls = new EffectiveIdentity(username: appLoginUserName, new List<string> { userDatasetId.ToString() });
                
                // Effective Identity
                var rolesList = new List<string>();
                rolesList.Add("Tenant");
                rls.Roles = rolesList;

                // Create list of datasets
                var v2DatasetID = new List<Guid>();
                v2DatasetID.Add(userDatasetId);

                // Create list of Effective Identities
                var v2rls = new List<EffectiveIdentity>();
                v2rls.Add(rls);

                // Create a request for getting Embed token 
                // This method works only with new Power BI V2 workspace experience
                var tokenRequest = new GenerateTokenRequestV2(

                    reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(report.Id) },

                    datasets: v2DatasetID.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),

                    identities: v2rls,

                    targetWorkspaces: null


                );

                // Generate Embed token
                var getToken = client.EmbedToken.GenerateToken(tokenRequest);
                

                // Populate embed variables (to be passed client-side)
                //embedToken = tokenResponse.Token;
                embedToken = getToken.ToString();
                embedUrl = report.EmbedUrl;
                reportId = report.Id;

            }
  1. Following is the Power BI embed configuration with dynamic dataset:
        <script>
            // Read embed token
            var embedToken = "<% =this.embedToken %>";

            // Read embed URL
            var embedUrl = "<% = this.embedUrl %>";

            // Read report Id
            var reportId = "<% = this.reportId %>";

            // Read dataset Id
            var userDatasetId = "<% = this.userDatasetId %>";

            // 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 config = {
                type: 'report',
                tokenType: models.TokenType.Embed,
                accessToken: embedToken,
                embedUrl: embedUrl,
                id: reportId,   
                datasetId: userDatasetId, // The dataset id that you want the report to use 
                settings: {
                    filterPaneEnabled: true,
                    navContentPaneEnabled: true,
                    extensions: [
                        {
                            command: {
                                name: "cmdShowValue",
                                title: "Show Value in MessageBox",
                                selector: {
                                    $schema: "http://powerbi.com/product/schema#visualSelector",
                                    visualName: "VisualContainer7" // Sales and Avg Price by Month visual
                                },
                                extend: {
                                    visualContextMenu: {
                                        title: "Show Value in MessageBox"
                                    }
                                }
                            }
                        }
                    ]

                }
            };

            // Embed the report within the div element
            var report = powerbi.embed(embedDiv, config);
            
        </script>
Feb 21, 2022 in Power BI by surbhi
• 3,810 points
1,932 views

1 answer to this question.

0 votes

This is not an option. These are report-wide settings, and you're wondering how two distinct users can connect to different data sources while seeing the same report at the same time. You can either make one report using all of the data sources and then filter the data based on the currently logged in user, or you can build one report using all of the data sources and choose which one to embed.

Otherwise, rebinding the report or changing the dataset's datasource is the direct answer to your question.

Unlock the Power of Data Visualization with Our Comprehensive Power BI Course!

answered Feb 21, 2022 by CoolCoder
• 4,400 points

Related Questions In Power BI

0 votes
1 answer

How to create a new dashboard by pinning visualizations from a report in Power BI?

Hey, I can show some steps wise steps ...READ MORE

answered Feb 6, 2020 in Power BI by Gitika
• 65,910 points
875 views
0 votes
1 answer

How to assign Power BI license to a new user

The assign license method of MS Graph API might ...READ MORE

answered Sep 25, 2018 in Power BI by Kalgi
• 52,360 points
671 views
0 votes
1 answer

How to publish .pbix report from power bi desktop to power bi service directly?

To save powerbi file directly to report ...READ MORE

answered Sep 27, 2018 in Power BI by Kalgi
• 52,360 points
1,747 views
0 votes
1 answer

How to add an image to power bi report – power bi web

There are visuals (e.g. table) that can ...READ MORE

answered Sep 27, 2018 in Power BI by Kalgi
• 52,360 points
1,185 views
0 votes
1 answer

Displaying Table Schema using Power BI with Azure IoT Hub

Answering your first question, Event Hubs are ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,007 views
+1 vote
1 answer

Unable to install connector for Power Bi and PostgreSQL

I think the problem is not at ...READ MORE

answered Aug 22, 2018 in Power BI by nirvana
• 3,130 points
2,471 views
+2 votes
2 answers

Migrate power bi collection to power bi embedded

I agree with Kalgi, this method is ...READ MORE

answered Oct 11, 2018 in Power BI by Hannah
• 18,570 points
1,146 views
+1 vote
1 answer

Connect power bi desktop to dataset and create custom reports

Yes using Power BI REST API to ...READ MORE

answered Sep 18, 2018 in Power BI by Kalgi
• 52,360 points
1,429 views
0 votes
1 answer

If there a way to have the current month by default in a KPI representing MoM% in Power BI

The PREVIOUSMONTH DAX function can be used ...READ MORE

answered Feb 16, 2022 in Power BI by CoolCoder
• 4,400 points
1,901 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP