TBH
TBH

Reputation: 33

Invalid filter value on Power BI chart

I'm using a Power BI embedded chart, with filters passed in from Javascript. Because of the way the filters are defined in a database, there is a possibility that a filter could be applied with the wrong type (a string supplied for a filter that's expecting a integer, for example). If this happens then the filter is invalid, and not applied, meaning a user can potentially see information that they shouldn't.

The code for setting up the chart is:

    var powerBiDashboard = powerbi.load(embedContainer, config);

    powerBiDashboard.on('error', function () {
        console.log('error');
    });

      powerBiDashboard.on('loaded', function (event) {

        console.log('Loaded');

        powerBiDashboard.setFilters(
            [{  $schema: "http://powerbi.com/product/schema#basic",
                filterType: 1,
                target:
                    { table: "DummyData", column: "Count" },
                operator: "In",
                values: ["150"],
                displaySettings: { isLockedInViewMode: true }
            }])
            .catch(function (errors) {
            console.log(errors);
        });

        powerBiDashboard.render();
    });
 

(note the incorrect value of "150" for the integer filter)

This produces a chart with this in the filter:

Invalid Filter

...instead of:

Valid Filter

If this happens, I want to not display the chart, and instead navigate away to an error page.

So... how can I tell if the filter is invalid? The error event doesn't get fired on the powerBiDashboard object, and the catch on the setFilters method call doesn't get executed either. And I can't find any properties on the powerBiDashboard object that would help.

Thanks.

Upvotes: 1

Views: 789

Answers (1)

mayur_007X
mayur_007X

Reputation: 784

First of all, Power BI JS filters are not recommended to be used with sensitive data. Instead, apply RLS on report.

As of today, the Power BI JS does not have this feature where invalid filter values throw exceptions. The Power BI Embedded team is aware of this scenario and they will add support for it in future releases.

To circumvent the scenario today, you can check the type of value before applying and accordingly show warnings/errors to users.

Visit docs for more details about applying filters using Power BI JavaScript.

Upvotes: 3

Related Questions