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

如何在PowerBI的Deneb(Vega-Lite)中按选择聚合文本列?

PowerBI Deneb(Vega-Lite)实现选中/全量文本聚合方案

核心实现思路

  • 通过Vega-Lite的选择交互捕获用户选中的柱子数据
  • 新增计算字段判断选中状态:无选中时聚合所有行文本,有选中时仅聚合选中行文本
  • 将聚合结果作为新列绑定到数据集,确保每行显示统一的聚合值

完整Vega-Lite配置代码

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"name": "dataset"},
  "selection": {
    "bar_select": {
      "type": "multi",
      "encodings": ["x"],
      "on": "click",
      "toggle": true
    }
  },
  "transform": [
    {
      "window": [
        {"op": "values", "field": "your_text_field", "as": "all_texts"}
      ]
    },
    {
      "calculate": "length(bar_select.selected) > 0 ? join(bar_select.selected[0].values, ', ') : join(all_texts, ', ')",
      "as": "aggregated_text"
    }
  ],
  "mark": {"type": "bar", "fill": "#4285F4"},
  "encoding": {
    "x": {"field": "your_category_field", "type": "nominal"},
    "y": {"field": "your_numeric_field", "type": "quantitative"},
    "color": {
      "condition": {"selection": "bar_select", "value": "#EA4335"},
      "value": "#4285F4"
    },
    "tooltip": [
      {"field": "your_category_field", "type": "nominal"},
      {"field": "your_numeric_field", "type": "quantitative"},
      {"field": "aggregated_text", "type": "nominal", "title": "聚合文本"}
    ]
  }
}

关键配置说明

  • 字段替换:将代码中your_text_field替换为实际需要聚合的文本列名,your_category_field替换为柱状图X轴的分类列名,your_numeric_field替换为Y轴的数值列名
  • 交互设置:bar_select选择器支持多选,点击柱子切换选中状态,仅捕获X轴分类的选中项
  • 聚合逻辑:
    • 用join()函数拼接文本值,分隔符为,
    • 通过length(bar_select.selected)判断是否有选中项:有选中时取选中集合的文本值,无选中时取所有行的文本值
  • 视觉反馈:选中的柱子会变色,tooltip中新增聚合文本字段展示结果

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 16:10:00