cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

Embed Report Filter not working

Hi,

 

I have read several posts and tried many examples and none of them are filtering my report. Below are a couple examples. Please help.

 

var accessToken = "@Model.EmbedToken.Token";

    // Read embed URL from Model
    var embedUrl = "@Html.Raw(Model.EmbedUrl)";

    // Read report Id from Model
    var embedReportId = "@Model.Id";

    // Get models. models contains enums that can be used.
    var models = window['powerbi-client'].models;

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

    if ("@Model.Username" != "") {
        $("#RLS").prop('checked', true);
        $("#RLSdiv").show();
    }
    else
    {
        $("#RLS").prop('checked', false);
        $("#RLSdiv").hide();
    }

    if ("@Model.IsEffectiveIdentityRequired.GetValueOrDefault()" == "True") {
        $("#noRLSdiv").hide();
        $("#RLS").removeAttr("disabled");
        $("#RLS").change(function () {
            if ($(this).is(":checked")) {
                $("#RLSdiv").show(300);
            } else {
                $("#RLSdiv").hide(200);
            }
        });
    }
    else
    {
        $("#noRLSdiv").show();
    }

    const testFilter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "SampleParameter",
            column: "AgentID"
        },
        operator: "In",
        values: ["H1627"]
    };

    // Embed configuration used to describe the what and how to embed.
    // This object is used when calling powerbi.embed.
    // This also includes settings and options such as filters.
    // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
    var config = {
        type: 'report',
        tokenType: models.TokenType.Embed,
        accessToken: accessToken,
        embedUrl: embedUrl,
        id: embedReportId,
        permissions: models.Permissions.All,//models.Permissions.Read
        //can add filters here
        filters: [testFilter], //filter array here
        settings: {
            filterPaneEnabled: true,
            navContentPaneEnabled: true //the nav at bottom of report
        },
        //filterType: models.FilterType.BasicFilter
    };

    // Embed the report and display it within the div container.
    var report = powerbi.embed(reportContainer, config);

 

// 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: "SampleParameter",
            column: "AgentID"
        },
        operator: "In",
        values: ["H1627"]
};
 
// Get a reference to the embedded report HTML element
var embedContainer = $('#embedContainer')[0];
 
// Get a reference to the embedded report.
report = powerbi.get(embedContainer);
 
// Set the filter for the report.
// Pay attention that setFilters receives an array.
report.setFilters([filter])
    .then(function () {
        Log.logText("Report filter was set.");
    })
    .catch(function (errors) {
        Log.log(errors);
    });
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
New Member

Re: Embed Report Filter not working

Data Model:

 

PowerBIDMR.png

 

Filter from design time in Power BI Desktop (but I can remove this and remember I mentioned that other columns not already added do not work):

 

jrichardsherita_0-1593462936512.png

Yes the value exists and yes the filter works as expected. Is anything else required?

View solution in original post

5 REPLIES 5
Highlighted
Resolver II
Resolver II

Re: Embed Report Filter not working

Hi @jrichardsherita 

I can see one potential issue...
The filter object doesn't contain a 'filterType' property. https://github.com/Microsoft/PowerBI-JavaScript/wiki/Filters

 

I have a working example that effectively matches what you have... with that one exception.
Filter types are as follows:

export enum FilterType {
  Advanced = 0,
  Basic = 1,
  Unknown = 2,
  IncludeExclude = 3, // currently not supported
  RelativeDate = 4,
  TopN = 5,
  Tuple = 6,
  RelativeTime = 7
}

 
So your full example should be:

const testFilter = {
    $schema: "http://powerbi.com/product/schema#basic",
    target: {
        table: "SampleParameter",
        column: "AgentID"
    },
    operator: "In",
    values: ["H1627"],
    filterType: 1
};

 
If you are using TypeScript - you can also reference the pbi.models enum values for these

filterType: pbi.models.FilterType.Basic

 
Hopefully this fixes it.

Highlighted
New Member

Re: Embed Report Filter not working

Thank you very much for the reply. Unfortuneately, that does not fix the issue. What happens is this filter puts 'AgentID' in the 'Filters on all pages' pane with a warning icon and obviously the report is not filtered. Using developer tools, that icon has a symbolid="fieldListError" and href="#fieldListError". I do not know what that means. I can change the filter to another column on the report and I will get the same issue. The code is in javascript. Is more content needed? Any other suggestions?

Highlighted
Resolver II
Resolver II

Re: Embed Report Filter not working

It's a bit tricky to diagnose without seeing the data model and relationships etc...

A couple of questions though...
Does that filter (AgentID) already exist as an available filter in the filter panel? (e.g. is it there at design time in Power BI Desktop)

And does the value that you are supplying exist within the available options -> Is it listed if you add the field as a filter in Power BI Desktop. + Does the filter work as expected (outside of the embedded environment)?

Highlighted
New Member

Re: Embed Report Filter not working

Data Model:

 

PowerBIDMR.png

 

Filter from design time in Power BI Desktop (but I can remove this and remember I mentioned that other columns not already added do not work):

 

jrichardsherita_0-1593462936512.png

Yes the value exists and yes the filter works as expected. Is anything else required?

View solution in original post

Highlighted
Resolver II
Resolver II

Re: Embed Report Filter not working

In your code sample, the table/column values are set to 'SampleParameter' + 'AgentID'

Your data model shows that field belonging to a table called 'ADW Agent DimCom....'

You will need to make sure that the table/column names are correct before anything else.
If this isn't the issue... then I will try and spend a few minutes later on today - and try and replicate what you are seeing.

Helpful resources

Announcements
May 2020 Community Highlights

May 2020 Community Highlights

It’s time for another PBI Community recap!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!