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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
thomasbenny
Regular Visitor

Dynamic filtering on Power BI Embedded

 

I have a report Embedded on my internal application, and i want filter based on user/group login to show the data, unfortunatly its not running very well, the report showing well but its not filtering as it code.

 

Below is my javascript code on embed powerBI, please do help me to solved this issue or anything would very appreciated.

 

<script>


    // 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 = "25f8b577-81fd-4769-8a3f-XXXXXXXX";

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

    // 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,
        pageView: "oneColumn",
        permissions: models.Permissions.All,        
        pageView: "oneColumn",
        settings: {
            filterPaneEnabled: true,
            navContentPaneEnabled: false
        }
    };

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

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

      var basicFilter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "M_Merchants",
            column: "Merchant_ID"
        },
        operator: 'In',
        values: "['119','120']",
        filterType: 0 
    };

    report.getFilters().then(function (allTargetFilters) {
        allTargetFilters.push(basicFilter);

        // Set filters
        // https://microsoft.github.io/PowerBI-JavaScript/interfaces/_src_ifilterable_.ifilterable.html#setfilters
        report.setFilters(allTargetFilters);
    });

   
</script>

Thanks,

Thomas Benny

1 REPLY 1
thomasbenny
Regular Visitor

<script>


    // 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 = "25f8b577-81fd-4769-8a3f-8383bbd5c176";
    var embedReportId = "44adc0f5-fafe-488d-b948-d1f78054456d";
    // Get models. models contains enums that can be used.
    var models = window['powerbi-client'].models;

    // 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.

    const basicFilter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "M_Company",
            column: "Company_ID"
        },
        operator: "In",
        values: [2],
        filterType: 0
    };
    var config = {
        type: 'report',
        tokenType: models.TokenType.Embed,
        accessToken: accessToken,
        embedUrl: embedUrl,
        id: embedReportId,
        pageName: 'M_Company',
        permissions: models.Permissions.All,
        filters: [basicFilter],
        settings: {
            filterPaneEnabled: false,
            navContentPaneEnabled: false
        }
    };

    var reportContainer = $('#reportContainer')[0];
    var report = powerbi.embed(reportContainer, config);

    //Add filter to the report
    report.on('loaded', event => {
        report.getFilters()
            .then(filters => {
                filters.push(basicFilter);
                return report.setFilters(filters);
            });
    });
  
</script>

when i add the filter on config, it continues loading with no end, I really dont undertand about this please somebody help me.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.