0
votes

I am new to power bi.

I have implemented multiple simple power bi reports where back-end is IMPORT not Direct Query and with Excel-sheet.

I have also embedded them successfully using power bi embedded and IFrame. Now I have a challenges:

I want to filter my reports by date range.

before loading report using power bi embedded or IFrame, I want to apply two filters fromdate and todate. these filters value will be chosen from web app datepicker, then on click of load, i want to show my report by applying these filters.

I have gone through following links, but still not understanding how to implement this:

Power BI Embed URL-multiple filters

https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details

1

1 Answers

0
votes

Even i got the same requirement where we have embedded report and from client side we have date range picker. Once you select date range then your report should filter. I tried to do it pushing dates manually and it worked, which is from javascript. Below is the sample code

    var fromDate = new Date("2011/10/30");
    fromDate = fromDate.toJSON();
    var toDate = new Date("2011/02/01");
    toDate = toDate.toJSON();

    $predefinedFilter1.on('click', function (event) {
        var models = window['powerbi-client'].models;
        const advancedFilter = new models.AdvancedFilter({
            table: "Time",
            column: "Date"
        }, "And", [
          {
              operator: "GreaterThan",
              value: fromDate
          },
          {
              operator: "LessThan",
              value: toDate
          }
        ]);
        //report.page("ReportSection3").setFilters([advancedFilter])
        report.setFilters([advancedFilter])
          .catch(errors => {
              // Handle error
          });
    }); 

Hope you can understand this.