如何在数据透视表中具有多列的小计中找到百分比

时间:2019-06-05 12:54:41

标签: excel pivot-table dax powerpivot

如何在数据透视表中具有多列的小计中找到百分比。

PercentYes :=
    CALCULATE ( SUM ( MyTable[value] ), MyTable[answers] = "yes" ) /
    CALCULATE (
        SUM ( MyTable[value] ),
        ALL ( MyTable[subcategory], MyTable[answers] )
    )

enter image description here

1 个答案:

答案 0 :(得分:1)

我创建了一个值样本

enter image description here

我首先创建一个总和度量:

Sum of Values:=SUM(MyTable[Value])

然后,我将创建百分比度量:

Percent of Values :=
DIVIDE (
    [Sum of Values],
    CALCULATE (
        [Sum of Values],
        ALL ( MyTable[Subcategory],MyTable[Answers] )            
    )
)

使用DIVIDE将有助于在分母中捕获零错误。结果看起来像这样:

enter image description here