Is it possible to get reports by filtering using power bi rest api?

邮差的信 提交于 2021-01-29 10:05:48

问题


Is it possible to get reports by filtering using power bi rest api? I want to embed power bi reports filtering by records. I can't see any option on power bi rest api, then how to get all reports by filter and embed reports in my application?

Since I am using powerbi.js as javascript client so below is my sample code: https://github.com/Microsoft/PowerBI-JavaScript

    var tokenType = 'embed';

    // Get models. models contains enums that can be used.
    var models = window['powerbi-client'].models;

    // We give All permissions to demonstrate switching between View and 
    //Edit mode and saving report.
    var permissions = models.Permissions.All;

    var config = {
        type: 'report',
        tokenType: tokenType == '0' ? models.TokenType.Aad : 
        models.TokenType.Embed,
        accessToken: txtAccessToken,
        embedUrl: txtEmbedUrl,
        id: txtEmbedReportId,
        permissions: permissions,
        settings: {
            filterPaneEnabled: true,
            navContentPaneEnabled: true
        }
    };

    // Get a reference to the embedded report HTML element
    var embedContainer = $('#embedContainer')[0];

    // Embed the report and display it within the div container.
    var report = (<any>window).powerbi.embed(embedContainer, config);

回答1:


When you are embedding a report, you can use the Embed Configuration to apply filters when the report is loaded. You can also change the filters dynamically later.

Here is a quote from filters wiki:

Filters are JavaScript objects that have a special set of properties. Currently, there are five types of filters: Basic, Advanced, Relative Date, Top N and Include/Exclude, which match the types of filters you can create through the filter pane. There are corresponding interfaces IBasicFilter, IAdvancedFilter, IRelativeDateFilter, ITopNFilter and IIncludeExcludeFilter, which describe their required properties.

For example, your filter can be constructed like this:

const basicFilter: pbi.models.IBasicFilter = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "Sales",
    column: "AccountId"
  },
  operator: "In",
  values: [1,2,3],
  filterType: pbi.models.FilterType.BasicFilter
}

You should pass this filter in report's configuration filters property.



来源:https://stackoverflow.com/questions/53720478/is-it-possible-to-get-reports-by-filtering-using-power-bi-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!