Forum Discussion

MichaelWash's avatar
MichaelWash
Helper I
4 years ago
Solved

Paginated Report embedding using a Power BI Dataset - How to pass the xmlaPermissions parameter?

Microsoft announced:  Support Power BI dataset as a data source for embedding paginated reports   It indicates: When embedding a paginated report with a Power BI dataset as a datasource for the ...
  • MichaelWash's avatar
    MichaelWash
    4 years ago

    This code works:

     

     

    public EmbedToken GetEmbedToken(PowerBIClient pbiClient, Guid reportId, Guid datasetId, Guid targetWorkspaceId)
    {
            EmbedToken embedToken = new EmbedToken();
    
            try
            {
                // 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(reportId) },
    datasets: new List<GenerateTokenRequestV2Dataset>() 
    { new GenerateTokenRequestV2Dataset(datasetId.ToString(), "ReadOnly") },
    targetWorkspaces: targetWorkspaceId != Guid.Empty ? new List<GenerateTokenRequestV2TargetWorkspace>() { 
       new GenerateTokenRequestV2TargetWorkspace(targetWorkspaceId) } : null,
    
       identities: new List<EffectiveIdentity> {
       // This first EffectiveIdentity is needed only if 
       // the Dataset uses Row Level Security
          new EffectiveIdentity(
              username: "[email protected]",
              roles: new List<string> { "A Role" },
              datasets: new List<string> { datasetId.ToString() }
           ), 
           new EffectiveIdentity(
           username: "[email protected]" ,
           reports: new List<string> { reportId.ToString() } 
           ) 
          }
         );
    
                // Generate Embed token
                embedToken = pbiClient.EmbedToken.GenerateToken(tokenRequest);
            }
            catch (Exception ex)
            {
                string errorMessage = ex.GetBaseException().Message;
            }
    
            return embedToken;
        }