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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Power BI Embedded - Filters

Hello All,

                Greetings, I had been created an Alert Data report with two parameters such as Start Date and End Date, the scenario of the report is that the user will first select the Start Date and End Date, and according to that date range the report will be displayed for that particular data. The report was working fine and I had published it to the Power BI Service too and there also the parameters are perfectly working.

 
              I had embedded that report into an Asp.Net MVC application using one of the Power BI developer samples [App Owns Data] in GitHub. The report had been embedded and working fine. The issue is, the parameters are not working in the Power BI Embedded. In the web app I had created 2 list boxes for the Start Date and End Date and a button, the report will be displayed once the user selects the dates from the list boxes and clicks the button. I have used the javascript to set the filters for the parameters but the filters are not reflected in the report.
 
Requesting for a solution or suggestion to accomplish this scenario. I have attached the code for reference.
 
const filter1 =
            {
                $schema: "http://powerbi.com/product/schema#advanced",
                target: 
                {
                    table: "Alert",
                    column: "Date"
                },
                logicalOperator: "And",
                conditions: 
                [
                    {
                        operator: "GreaterThanOrEqual",
                        value: sd
                    },
                    {
                        operator: "LessThanOrEqual",
                        value: ed
                    }
                ],
            };

            var reportContainer = $('#reportContainer')[0];

            var report = powerbi.embed(reportContainer, config);

            //report.on('loaded', event => { report.getFilters().then(filters => { filters.push(filter1); return report.setFilters(filters); }) });

            report.setFilters([filter1]);
6 REPLIES 6
dkumar346
Regular Visitor

Hi,

 

I implemented Embedded-filter in my reports too. but it is not working since today morning. I went to the demo site but it is also not working here, Please update us if Microsoft is making some changes in embedded filter option.

 

https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/index.html#

 

regards

Deepak Kumar Mishra

deepak@gs1india.org

Anonymous
Not applicable

Any solutions to this question...

 

Regards,

Geetha

v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

I would suggest you try the online demo here. You also can download the source code. It could be like below.

// Build the filter you want to use. For more information, See Constructing
// Filters in https://github.com/Microsoft/PowerBI-JavaScript/wiki/Filters.
const filter = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "Store",
    column: "Chain"
  },
  operator: "In",
  values: ["Fashions Direct"]
};

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

// Get a reference to the embedded report.
report = powerbi.get(embedContainer);

// Retrieve the page collection and get the visuals for the first page.
report.getPages()
  .then(function (pages) {

    // Retrieve active page.
    var activePage = pages.find(function(page) {
      return page.isActive
    });

    activePage.getVisuals()
      .then(function (visuals) {

        // Retrieve the wanted visual.
        var visual = visuals.find(function(visual) {
          return visual.name == "VisualContainer3";
        });

        // Set the filter for the visual.
        // Pay attention that setFilters receives an array.
        visual.setFilters([filter])
            .catch(function (errors) {
                Log.log(errors);
            });
        })
        .catch(function (errors) {
            Log.log(errors);
        });
  })
  .catch(function (errors) {
      Log.log(errors);
  });

Best Regards,

Dale

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

Hai @v-jiascu-msft thank you for your response, I had already tried the online demo but yet I couldn't able to find the bug.

 

Kind Regards,

Geetha

Hi Geetha,

 

What is the type of the filter? If it's a visual level filter, we should get the report first and then get the page and the visual. At last we can set the filter. 

// Build the filter you want to use. For more information, See Constructing
// Filters in https://github.com/Microsoft/PowerBI-JavaScript/wiki/Filters.
const filter = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "Store",
    column: "Chain"
  },
  operator: "In",
  values: ["Fashions Direct"]
};

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

// Get a reference to the embedded report.
report = powerbi.get(embedContainer);

// Retrieve the page collection and get the visuals for the first page.
report.getPages()
  .then(function (pages) {

    // Retrieve active page.
    var activePage = pages.find(function(page) {
      return page.isActive
    });

    activePage.getVisuals()
      .then(function (visuals) {

        // Retrieve the wanted visual.
        var visual = visuals.find(function(visual) {
          return visual.name == "VisualContainer3";
        });

        // Set the filter for the visual.
        // Pay attention that setFilters receives an array.
        visual.setFilters([filter])
            .catch(function (errors) {
                Log.log(errors);
            });
        })
        .catch(function (errors) {
            Log.log(errors);
        });
  })
  .catch(function (errors) {
      Log.log(errors);
  });

Best Regards,

Dale

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

Hi @v-jiascu-msft, it is a Report level filter...

 

Kind Regards,

Geetha

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

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