首页 > 解决方案 > 如何在 Power BI 中使用 DAX 中的筛选器计算百分比?

问题描述

我有两列

CustomerCode | Segmentation

AU656 | abc
AU765 | cdf
AU563 | abc
AU235 | abc
AU324 | opr
AU908 | opr
AU123 | pqr
AU234 |pqr 

我必须找到一个不同的 CustomerCode 计数,其中分段是“abc”、“cdf”和“pqr”,并将其除以 CustomerCodes 的总数(全部)。

我创建了一个度量 -

#RSP =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustomerCode] ),
    FILTER ( ALL ( 'Table' ), 'Table'[Segmentation] = "abc" ),
    'Table'[Segmentation] = "cdf",
    'Table'[Segmentation] = "opr"
)

但是,这没有任何价值。我是否使用错误的过滤器?我该如何计算?

标签: powerbidaxpowerbi-desktop

解决方案


您的度量失败,因为分段不能同时是多个值。试试这个:

#RSP =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustomerCode] ),
    'Table'[Segmentation] IN { "abc", "cdf", "opr" }
)
Ratio = DIVIDE ( [#RSP], DISTINCTCOUNT ( 'Table'[CustomerCode] ) )

推荐阅读