添加新的主模型和子模型后排序不起作用

问题描述 投票:0回答:1

我之前的问题可以在Deneb (Vega-lite) - Sorting Axis找到。

davidebacci 的答案帮助我仅使用一个主要模型对数据集中的子模型进行排序。 添加新的主模型和子模型后,排序不起作用。请参阅下面的屏幕截图。

这里的目标是主要模型显示其子模型的总和,然后在每个主要模型下,其子模型按降序排序。

我还没有尝试过的一个想法(或潜在的解决方案)是使用“facet”或“repeat”。不过在尝试之前,我还是想听听专家的意见,是否还能用分层来实现排序。

PBI 文件可以在 https://github.com/triCNguyen5/Test/blob/main/sortingAxisLabels.pbix

找到

enter image description here

powerbi visualization powerbi-desktop vega-lite deneb
1个回答
0
投票

enter image description here

{
  "data": {
    "name": "dataset"
  },
  "encoding": {
    "y": {
      "field": "ui_label",
      "type": "nominal",
      "sort": {
        "field": "rank",
        "order": "ascending",
        "op": "min"
      }
    },
    "x": {
      "field": "EventRate",
      "type": "quantitative"
    },
    "text": {
      "field": "EventRate",
      "type": "quantitative"
    }
  },
  "transform": [
    {
      "calculate": "datum.model",
      "as": "major_model"
    },
    {
      "calculate": "format(datum.EventRate + 10000, '.5f') + '|' + datum.ui_label",
      "as": "minor_model"
    },
    {
      "sort": [
        {
          "field": "EventRate",
          "order": "descending"
        }
      ],
      "window": [
        {
          "op": "rank",
          "as": "rank1"
        }
      ],
      "groupby": [
        "model"
      ]
    },
    {
      "joinaggregate": [
        {
          "op": "sum",
          "field": "EventRate",
          "as": "TotalEventRate"
        }
      ],
      "groupby": [
        "model"
      ]
    },
    {
      "sort": [
        {
          "field": "TotalEventRate",
          "order": "descending"
        }
      ],
      "window": [
        {
          "op": "dense_rank",
          "as": "rank"
        }
      ]
    },
    {
      "calculate": "(datum.rank1/10)+datum.rank",
      "as": "rank"
    }
  ],
  "layer": [
    {
      "transform": [
        {
          "aggregate": [
            {
              "op": "sum",
              "field": "EventRate",
              "as": "EventRate"
            },
            {
              "op": "max",
              "field": "rank1",
              "as": "maxRank"
            }
          ],
          "groupby": [
            "model"
          ]
        },
        {
          "sort": [
            {
              "field": "EventRate",
              "order": "descending"
            }
          ],
          "window": [
            {
              "op": "rank",
              "as": "rank"
            }
          ]
        },
        {
          "calculate": "datum.model",
          "as": "ui_label"
        }
      ],
      "layer": [
        {
          "name": "Major Model Bar",
          "mark": {
            "type": "bar",
            "color": "#004D45",
            "height": 20,
            "tooltip": true
          }
        },
        {
          "name": "Major Model Event Rate Label",
          "mark": {
            "type": "text",
            "align": "left",
            "dx": 5,
            "baseline": "middle"
          }
        }
      ]
    },
    {
      "name": "Minor Model Bar",
      "mark": {
        "type": "bar",
        "color": "#8FC319",
        "height": 15,
        "tooltip": true
      }
    },
    {
      "name": "Minor Model Event Rate Label",
      "mark": {
        "type": "text",
        "align": "left",
        "dx": 5,
        "baseline": "middle"
      }
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.