按类别分类的 Power BI 不同值总和

时间:2021-06-19 18:30:09

标签: powerbi dax

我有 n 种浆果。每种浆果类型都有一个累积值。我需要按浆果类型计算不同积累值的总和。对于“累积计算”(下图),我总共需要 10 (5 + 3 + 2)。

  • 我使用的 DAX 公式:accumulation calc = sumx(VALUES(berries[type]), MAX(berries[accumulation]))
  • 我如何指示 DAX 按单个浆果类型求和 max 或不同?目前它似乎默认为 blueberry 并计算 5 + 5 + 5 而不是 5 + 3 + 2。

有大佬指点一下吗? enter image description here

1 个答案:

答案 0 :(得分:1)

由于您只想对每种浆果类型的 Max 值进行小计,因此最好创建一个 summary 表来获取单个浆果类型和类型的最大值:

新表的 Dax 度量:

Table 2 = SUMMARIZE(Sheet1,Sheet1[Berry],"Max value",
            CALCULATE(MAX(Sheet1[accumulation]),
              FILTER(Sheet1,Sheet1[Berry]=EARLIER(Sheet1[Berry]))))

新表格:

enter image description here

示例数据:

enter image description here