Search code examples
powerbipowerbi-embedded

PowerBI updateFilters is not working on Embedded Visuals


I am trying to get the Slicer Filters and then apply the filters on each of the visuals separately embedded into my Page. But I am getting an error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Add')

Code:

async function UpdateFilters(event) {
    var filters = [];
    for (var i = 0; i < powerbi.embeds.length; i++){
    
        var x = await powerbi.embeds[i].getVisualDescriptor()
        console.log(x);
        if (x.type == 'slicer') {

            var f = await x.getSlicerState();
            filters.push(f);
        }
    }


    for (var i = 0; i < powerbi.embeds.length; i++) {

        var x = await powerbi.embeds[i].getVisualDescriptor();
        for (let i = 0; i < filters.length; i++) {
            await x.updateFilters(models.FiltersOperations.Add, [filters[i]]);
        }
    }
    console.log(filters);
}

Solution

  • Solved this by using the latest powerbi-client JS

    Link: https://cdnjs.cloudflare.com/ajax/libs/powerbi-client/2.19.1/powerbi.min.js