Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
GouthamPamula
New Member

apply filters to power bi report using power bi javascript api

I'm applying custom  filters for power bi report  using some javascript code. but filters are not applying . Im getting powerbi report on browser without any filter.

I'm following Javascript code here :

 

filterreport02.PNG

below one is sample code which iam using .

 

 

 

 

<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/jquery/dist/jquery.js"></script>
<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/powerbi-client/dist/powerbi.js"></script>
<script type="text/javascript">
window.onload = function () {
    var models = window['powerbi-client'].models;
const basicFilter  = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "TableName",
    column: "ColumnName"
  },
  operator: "In",
  values: ["Jr.Software"],
  filterType: models.FilterType.Basic,
  requireSingleSelection: true
}
var embedConfiguration = {
    type: 'report',
tokenType: models.TokenType.Embed,
    id: reportId,
    accessToken: '{myToken}',
    embedUrl: 'https://app.powerbi.com/view?{-------}&pageName=ReportSection',
 permissions: models.Permissions.All,
		filters:[basicFilter],
        settings: {
            filterPaneEnabled: true,
            navContentPaneEnabled: true
        }
};
var $reportContainer = $('#reportContainer');
var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
report.updateFilters(models.FiltersOperations.Add,[basicFilter])
}
</script>

<div id="reportContainer"></div>
 

 

 

 

 

i need render power bi report with filters below like:
repr01.PNG

 

pls can anyone suggest where i have done mistake in above javascript code .
could you please provide any links .

 

thanks 
Goutham pamula

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @GouthamPamula ,

You can refer the following links to get it:

Control report filters

Addling filter using javascript API (Power BI Service)

Embed your Power BI report with predefined filters

const filter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "DimProduct",
            column: "ColorName"
        },
        operator: "In",
        values: ["Silver"]
    };
var config = {
              type: 'report',
              tokenType: models.TokenType.Embed,
              accessToken: accessToken,
              embedUrl: embedUrl,
              id: embedReportId,
              permissions: models.Permissions.All,
              settings: {
                            filterPaneEnabled: true,
                            navContentPaneEnabled: true
              }
};
// Embed the report and display it within the div container.
var report = powerbi.embed(reportContainer, config);
report.on('loaded', event => {
        report.getFilters()
            .then(filters => {
                filters.push(filter);
                return report.setFilters(filters);
            });

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @GouthamPamula ,

You can refer the following links to get it:

Control report filters

Addling filter using javascript API (Power BI Service)

Embed your Power BI report with predefined filters

const filter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "DimProduct",
            column: "ColorName"
        },
        operator: "In",
        values: ["Silver"]
    };
var config = {
              type: 'report',
              tokenType: models.TokenType.Embed,
              accessToken: accessToken,
              embedUrl: embedUrl,
              id: embedReportId,
              permissions: models.Permissions.All,
              settings: {
                            filterPaneEnabled: true,
                            navContentPaneEnabled: true
              }
};
// Embed the report and display it within the div container.
var report = powerbi.embed(reportContainer, config);
report.on('loaded', event => {
        report.getFilters()
            .then(filters => {
                filters.push(filter);
                return report.setFilters(filters);
            });

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for sharing the information

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.