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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Cobra77
Post Patron
Post Patron

Power BI Embedded Filter(s) Problem when you manage 1 filter on several on same zone

Hi

 

we use this code :

the code :


  if (accessToken && reportId && embedURL) {
    var embedConfiguration = {
        type: 'report',
        accessToken: accessToken,
        id: reportId,
        embedUrl: embedURL,
        settings: {
            filterPaneEnabled: false
       
}
    };

    window.powerbi.embed(document.getElementById('reportContainer'), embedConfiguration);

    if (projectName) {
        var Promise = require('es6-promise').Promise;
        var report = window.powerbi.get(document.getElementById('reportContainer'));

        report.on('loaded', function() {
            const filter = {
                $schema: "http://powerbi.com/product/schema#basic",
                target: {
                    table: "011 - Projets",
                    column: "01 - Projet"
               
},
                operator: "In",
                values: [projectName]
            };

            report.setFilters([filter]);

        });
    }
}

 

But if we have several filters on page report , the others filters disappear

 

We reactive panel to see in embedded : 

withembedded.jpg

 

in power bi .com we have 5 others filters : 

 

 

withsitepbi.jpg

 

 

An idea ?

 

Thanks

Best reagards

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @Cobra77,

 

The setFilters() will clear the old filters by default. I would suggest you try the workaround below. Get the old filters first and set the new filters as old filters plus new filters.

// 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: "DimProduct",
        column: "ClassID"
    },
    operator: "In",
    values: ["1"]
};

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

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

// Get old filters first.
report.getFilters()
    .then(function (old_filters) {
        report.setFilters(old_filters.concat([filter]))
            .catch(function (errors) {
                Log.log(errors);
            });
    })
    .catch(function (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.

View solution in original post

1 REPLY 1
v-jiascu-msft
Employee
Employee

Hi @Cobra77,

 

The setFilters() will clear the old filters by default. I would suggest you try the workaround below. Get the old filters first and set the new filters as old filters plus new filters.

// 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: "DimProduct",
        column: "ClassID"
    },
    operator: "In",
    values: ["1"]
};

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

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

// Get old filters first.
report.getFilters()
    .then(function (old_filters) {
        report.setFilters(old_filters.concat([filter]))
            .catch(function (errors) {
                Log.log(errors);
            });
    })
    .catch(function (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.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors