从 asp.net MVC 以编程方式将参数传递给双过滤器

passing parameters to power bi filter programmatically from asp.net MVC

我已经开发了一个 powerBI 报告并将其部署在 Workspace 中。
从 PowerBI 界面我查看了报告并能够添加这样的过滤器: filter=表名~2F列名eq 4 该条件在界面上运行良好。但是,当我在 asp.ner MVC 应用程序的代码中添加过滤条件时,过滤器不起作用。

从界面上看情况正常。 但是,当我在 asp.ner MVC 应用程序的代码中添加过滤条件时,过滤器不起作用。

我的示例代码:

var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials);
var reports = await client.Reports.GetReportsInGroupAsync(WorkspaceId);
report = reports.Value.FirstOrDefault(r => r.Id == "aa07v254-8t46-2387-4k53-2725y90n3456");

report.EmbedUrl = report.EmbedUrl + "?filter=tablename/columnname%20eq%204";

请帮我诊断一下,为什么过滤器不起作用。

您不需要更改嵌入 url,而是尝试使用以下示例:

// 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: "Geo",
        column: "Region"
    },
    operator: "In",
    values: ["West"]
};

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

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

// Set the filter for the report.
// Pay attention that setFilters receives an array.
report.setFilters([filter])
    .then(function () {
        Log.logText("Report filter was set.");
    })
    .catch(function (errors) {
        Log.log(errors);
    });