0
votes

I have embedded power bi report in my asp.net mvc application. It is working fine and it is showing data. I am having one issue, in my application every client has few branches like cities. Every user for that client may have access to all or some branches and based on that access we show data when that user is logged into system.

I want to achieve same in power bi that when user is logged into system and view reports it should show him/her data of branch he/she has access to. I found one solution [Can I pass a dynamic query parameter to an embedded Power BI report in ASP.Net MVC? where we can set filter values from program side. I applied this in my view but i am still getting all data.

    const branchFilter = {
        $schema: "http://powerbi.com/product/schema#basic",
        target: {
            table: "tblWorkhistory",
            column: "BranchID"
        },
        operator: "In",
        values: [1],
        filterType: models.FilterType.BasicFilter
    }

        var config = {
        type: 'report',
        tokenType: models.TokenType.Embed,
        accessToken: accessToken,
        embedUrl: embedUrl,
        id: embedReportId,
        permissions: models.Permissions.All,
        viewMode: models.ViewMode.View,
        filters: [branchFilter],
        settings: {
            filterPaneEnabled: true,
            navContentPaneEnabled: true
        }
    };

Here i want to apply filter where it will show data for only branch whose id is 1 but it is showing all data. Am i missing anything here? do i need to do anything report side also after this code?

Regards, Savan

2
You are missing the step, where you apply the declared filter, e.g. by calling report.setFilters([branchFilter]);Andrey Nikolov
That helped, thanks. It is working when i pass specific value as filter value, but not when i want to pass value which is assigned to any variable. i am using var currentBranchID = "@AppSession.Current.BranchID"; and in above branchFilter instead of static 1 i am using ` target: { table: "WorkHistory", column: "BranchID" }, operator: "In", values: currentBranchID` if i put currentBranchID in [ ] then it is returning all data and if remove [] then i am getting syntax error. Any way i can pass dynamic value.Savan Parmar

2 Answers

1
votes

Applying filter using embed config is supported, and the code sample you've shared seems valid.

If report.setFilters fails as well, seems like something with the filter is wrong.

Try to verify the data type of the filter, should it be 1 or "1"?

If this doesn't work, is there any error message being returned from .setFilters request?:

const filter = { ... };

report.setFilters([filter])
  .catch(errors => {
    // Handle error
  });

Learn more here about setting filters through JS SDK.

0
votes

To show data based on the user logged into you application you have to apply Row Level Security (RLS) in your power bi report first and then follow the steps from following article https://docs.microsoft.com/en-us/power-bi/developer/embedded-row-level-security