Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

The mystery behind PowerBI Tile dataset changing

The .NET PowerBI SDK offers the Tile class in the Microsoft.PowerBI.Api.Models namespace.

This Tile class, interestingly enough, has a DatasetId public property that has both a public getter and a public setter.

I have the following method below, which aims to ultimately return a custom made object of type PowerBITileEmbedInfo containing all rendering configuration values needed to the PowerBI JS SDK on the frontend side:

 

public async Task<PowerBITileEmbedInfo> GetDefaultTileEmbedInfo()
        {
                var currentUserId = 1;
// Get a list of dashboards. var dashboards = await m_PowerBIClient.Dashboards.GetDashboardsInGroupAsync(m_ReportsWorkspaceId); // Get the first report in the workspace. var dashboard = dashboards.Value.FirstOrDefault(); if (dashboard == null) { throw new NullReferenceException("Workspace has no dashboards"); } var tiles = await m_PowerBIClient.Dashboards.GetTilesInGroupAsync(m_ReportsWorkspaceId, dashboard.Id); // Get the first tile in the workspace. var tile = tiles.Value.FirstOrDefault(); string datasetId = tile.DatasetId; // Generate Embed Token for a tile. var effectiveIdentities = new List<EffectiveIdentity>(); var effectiveIdentity = new EffectiveIdentity() { Username = currentUserId.ToString(), Roles = new List<string>() { "Reader" }, Datasets = new List<string>() { datasetId } }; effectiveIdentities.Add(effectiveIdentity); var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identities: effectiveIdentities); var tokenResponse = await m_PowerBIClient.Tiles.GenerateTokenInGroupAsync(m_ReportsWorkspaceId, dashboard.Id, tile.Id, generateTokenRequestParameters); if (tokenResponse == null) { throw new NullReferenceException("Failed to generate embed token"); } // Generate Embed Configuration. var tileEmbedConfig = new PowerBITileEmbedInfo() { AccessToken = tokenResponse.Token, EmbedUrl = tile.EmbedUrl, TileId = tile.Id.ToString(), DashboardId = dashboard.Id.ToString() }; return tileEmbedConfig; }

 

I am basically assigning the DataSetId property that comes directly from the tile object to the datasetId variable that I subsequently use for my EffectiveIdentity (for RLS).

From my understanding, a tile is a part of a report which has a Dataset behind it.

My goal is to be able to change the dataset and thus have the tile's data reflect this accordingly. I would require it since the app I am developing is multi tenant and I would like to have the tile be relevant to a dataset linked with each tenant.

The PowerBI documentation available online is often blurry in terms of making it crisp clear when should one use V1 for generating the embed token, or when to use V2, or how to approach this.

Is it even possible to programmatically change the dataset behind a tile and have the UI data reflect this well enough ?

Do I need to first change the dataset behind the report out of which I'm getting the tile, and then attempt to get the tile ? If so, how can I correctly generate the embed token ?

P.S. I would speculate rebinding is not the way to go.

2 Replies