首页 文章

如何在PowerBI中使用GROUPBY功能?

提问于
浏览
2

我尝试在PowerBI中使用group by DAX函数作为Measure,New Column,New Table但是我在验证函数时遇到错误,

New Table = GROUPBY(
            'tab1',
            'tab1'[color],
            "Group By color",
            sum('tab1'[count_lables])
          )

Error : Function 'GROUPBY' scalar expressions have to be Aggregation functions over CurrentGroup(). The expression of each Aggregation has to be either a constant or directly reference the columns in CurrentGroup().

1 回答

  • 3

    该错误表示您需要在组上使用聚合函数,您正在使用 SUM 函数,该函数不会对任何组的值求和 . 在您的情况下,您需要使用 SUMX 聚合函数和 CURRENTGROUP() 选项 . CURRENTGROUP 确定必须根据当前行添加的组 .

    请尝试使用以下表达式 .

    New Table = GROUPBY (
            tab1,
            tab1[color],
            "Group by color", SUMX ( CURRENTGROUP (), tab1[count lables] )
        )
    

    如果这有帮助,请告诉我 .

相关问题