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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
paulhyland
Regular Visitor

I keep getting an error telling me "filters property is invalid" in embed configuration in VS

Here's all the javascript:

 

    // Read embed application token from Model
    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;

    // Set up filter for Response ID
    const filter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "ResponsesResultsUsers",
            column: "Response ID"
        },
        operator: "In",
        values: 26
    }
    // 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,
        filters: [filter],
        settings: {
            filterPaneEnabled: true,
            navContentPaneEnabled: false
        }
    };

    // Get a reference to the embedded report HTML element
    var reportContainer = $('#reportContainer')[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();
    }
    // Embed the report and display it within the div container.
    var report = powerbi.embed(reportContainer, config);

    report = powerbi.get(reportContainer);

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

It doesn't seem to recognize the "filters" property of the config object. The post-load application of the filter doesn't do anything either (if I comment out the "filters" property, then the report loads fine, but using the original value for "Response ID" not the one included in the "filter" contant declaration above.

 

It almost seems as though the filter support isn't included here. Could it be the use of powerbi-client vs. powerbi-models? the latter of which is referenced in the embedded filtering docs page.

3 REPLIES 3
Anonymous
Not applicable

i am facing an issue , when filter pane is hidden using updatesetting() api method , the filter pane appears when clicked inside report tiles , this looks like a bug from javascript library.anyone knows this issue or solution?

v-jiascu-msft
Employee
Employee

Hi @paulhyland,

 

The values could be in []. Please give it a try. Reference: https://github.com/Microsoft/PowerBI-JavaScript/wiki/Filters#constructing-filters

const filter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "ResponsesResultsUsers",
            column: "Response ID"
        },
        operator: "In",
        values: [26]
    }

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.
paulhyland
Regular Visitor

Here's all the javascript:

 

    // Read embed application token from Model
    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;

    // Set up filter for Response ID
    const filter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "ResponsesResultsUsers",
            column: "Response ID"
        },
        operator: "In",
        values: 26
    }
    // 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,
        filters: [filter],
        settings: {
            filterPaneEnabled: true,
            navContentPaneEnabled: false
        }
    };

    // Get a reference to the embedded report HTML element
    var reportContainer = $('#reportContainer')[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();
    }
    // Embed the report and display it within the div container.
    var report = powerbi.embed(reportContainer, config);

    report = powerbi.get(reportContainer);

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

It doesn't seem to recognize the "filters" property of the config object. The post-load application of the filter doesn't do anything either (if I comment out the "filters" property, then the report loads fine, but using the original value for "Response ID" not the one included in the "filter" contant declaration above.

 

It almost seems as though the filter support isn't included here. Could it be the use of powerbi-client vs. powerbi-models? the latter of which is referenced in the embedded filtering docs page.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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