0
votes

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
Could you explain what get all reports by filter means, please?Andrey Nikolov
for example, I have a report with dynamics crm account id and sales amount fields, now I want to filter report by account id, how to do such kind of filter in power bi report?user10496245
I do not understand how is this related to Power BI REST API. Do you want to pass filters in the URL? docs.microsoft.com/en-us/power-bi/service-url-filtersAndrey Nikolov
using Power BI REST API I can get embed url, is it possible to pass query parameter with this embed url?user10496245

1 Answers

0
votes

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.