Skip to content Skip to sidebar Skip to footer

How To Set Filters In Reports Power Bi Embedded Javascript

I want to add somes filters on my reports power bi embedded, i have an html file, and i need to add somes filters in javascript but i dont have experience as a developer. I just ne

Solution 1:

To filter your embed report, you must construct one or more filters and pass them as array to the JavaScript client - either in filters property of embedConfiguration, or as a parameter to report/page/visualsetFilters method.

The filters can be from one of these types:

  • IBasicFilter
  • IAdvancedFilter
  • IRelativeDateFilter
  • ITopNFilter
  • IIncludeExcludeFilter

For example, to filter table named Product to show only data, where Count column is 1, 2 or 3 can be constructed as follows:

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

Then modify your code to pass this filter to embedConfiguration:

varembedConfiguration= {  
    type:'report',  
    id:json.ReportId,  
    embedUrl:json.EmbedUrl,  
    tokenType:models.TokenType.Embed,  
    accessToken:json.EmbedToken,
    filters: [basicFilter]  
};

For more information about configuring the embed element, see Embed Configuration Details and to see more information on how to use different filter types and applying them, see Filters.

Solution 2:

@Andrey Nikolov

Thank you for your answer but i have an error when i add this line : filters: [basicFilter] to the Embedconfiguration for example in my case i want to filter just with table : "Contract" and column: "IdContract".

So it will be like that :

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

Then

varembedConfiguration= {  
    type:'report',  
    id:json.ReportId,  
    embedUrl:json.EmbedUrl,  
    tokenType:models.TokenType.Embed,  
    accessToken:json.EmbedToken,
    filters: [basicFilter]  
};

I dont know if this is what you meant...

Post a Comment for "How To Set Filters In Reports Power Bi Embedded Javascript"