Can I pass a dynamic query parameter to an embedded Power BI report in ASP.Net MVC?

£可爱£侵袭症+ 提交于 2020-05-14 11:54:08

问题


My question is in reference to the following documentation that is part of Power BI Embedded Query Parameters API at https://azure.microsoft.com/en-us/updates/power-bi-embedded-query-parameters-api/

"Note that the parameters are based on the dataset, so they are defined per report/dashboard, but not on the user’s session level. It means that different users who are using the same report at the same time will always see the same parameter’s value."

We are planning to Embed dashboards created using Power BI into our .Net MVC application. A lot of school users(external to the organization and from different schools) would be logging in to access these reports.

Let us assume that 5 users from 5 different schools are trying to access a dashboard that is parameterized to display data as per their school. Can I achieve this using power BI Embedded? The source of my confusion is that the documentation states that different users who are using the same report at the same time will always see the same parameter’s value.


回答1:


Parameters aren't good choice in this case. Using the API you can change their values, but these values are stored in the report itself and all users, who opens these reports, will be affected by the parameter value changes.

You should use filters to achieve that. Let's say you have a table named SchoolData in your model, and a column named SchoolId in it. When you embed the report in your application, define a filter for this column, e.g. like this:

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

And then pass this filter in embed configuration details:

var config = {
    type: embedType,
    accessToken: accessToken,
    tokenType: tokenType,
    embedUrl: embedUrl,
    id: embedId,
    dashboardId: dashboardId,
    permissions: permissions,
    filters: [basicFilter],
    settings: {
        filterPaneEnabled: true,
        navContentPaneEnabled: true
    }
};

where 1 is the value corresponding to the currently logged user. Change it every time, when the report is shown in your application, depending on the current user (i.e. 2, 3, 4, etc.).

More information on how to filter data with Power BI Embedded can be found in Filters documentation.



来源:https://stackoverflow.com/questions/54098774/can-i-pass-a-dynamic-query-parameter-to-an-embedded-power-bi-report-in-asp-net-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!