You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EmbededPowerBI React组件无法过滤报表数据求助

PowerBIEmbed 筛选JSON嵌套字段失效的解决办法

问题根源

你当前用的是基本过滤器(basic schema),它只能识别Power BI模型中存在的物理列,无法直接解析CustomColumnJson.Id这种嵌套JSON属性;另外values参数传了字符串,而In操作符要求传入数组格式。

解决方法

方法1:改用高级过滤器(无需修改Power BI模型)

把过滤器改成高级模式,用DAX表达式解析JSON字段里的Id值,代码修改如下:

<PowerBIEmbed
    embedConfig={{
        type: 'report', 
        id: '*********************',  //client_id
        embedUrl: "", //embed url
        accessToken: this.state.accessToken,
        tokenType: models.TokenType.Aad,
        filters: [{
            $schema: "http://powerbi.com/product/schema#advanced",
            target: {
                table: "Event"
            },
            logicalOperator: "And",
            conditions: [{
                expression: `JSONVALUE('Event'[CustomColumnJson], "$.Id")`,
                operator: "In",
                values: ["XYZ"] // 注意这里是数组格式
            }]
        }],
        settings: {
            panes: {
                filters: {
                    expanded: false,
                    visible: true
                }
            },
        }
    }} 
    eventHandlers={
        new Map([
            ['loaded', () => console.log('Report loaded')],
            ['rendered', () => console.log('Report rendered')],
            ['error', (event) => console.log(event.detail)]
        ])
    }
    cssClassName="container"
    getEmbeddedComponent={(embeddedReport) => {
        window.report = embeddedReport;
    }}
/>

核心变化:用JSONVALUE函数提取JSON中的Id字段,改用高级过滤器schema,values改为数组格式。

方法2:在Power BI模型中拆分JSON列(更稳定)

  1. 打开Power BI Desktop,找到Event表的CustomColumnJson列
  2. 点击「转换」选项卡 → 「解析JSON」,选择「作为对象」
  3. 展开生成的JSON结构,把Id和Event字段拆成单独的物理列
  4. 重新发布报表后,嵌入代码里的过滤器可以直接用基本模式:
filters: [{
    $schema: "http://powerbi.com/product/schema#basic",
    target: {
        table: "Event",
        column: "Id" // 直接用拆分后的物理列
    },
    operator: "In",
    values: ["XYZ"] // 保持数组格式
}]

内容的提问来源于stack exchange,提问作者vam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 05:10:30