如何在PowerBI中使用GROUPBY函数?

Dav*_* D. 5 dax powerbi

我尝试在PowerBI中将DAX组功能用作度量,新列,新表,但是在验证该功能时出现错误,

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().
Run Code Online (Sandbox Code Playgroud)

ale*_*eta 6

该错误表明您需要在组上使用聚合函数,而正在使用的SUM函数不会对任何组上的值求和。在您的情况下,您需要将SUMX聚合功能与CURRENTGROUP()option 一起使用。在CURRENTGROUP确定必须基于当前行上被添加的组。

请尝试使用以下表达式。

New Table = GROUPBY (
        tab1,
        tab1[color],
        "Group by color", SUMX ( CURRENTGROUP (), tab1[count lables] )
    )
Run Code Online (Sandbox Code Playgroud)

让我知道是否有帮助。

  • @DaveD。,欢迎您。当然,请查看Marco Russo撰写的[本文精彩](http://www.sqlbi.com/articles/nested-grouping-using-groupby-vs-summarize/)文章。 (2认同)