如何解决如何在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"
)
但是,这没有任何价值。我使用的过滤器是否错误? 我该如何计算?
解决方法
您的测量失败,因为细分不能同时是多个值。尝试以下方法:
#RSP =
CALCULATE (
DISTINCTCOUNT ( 'Table'[CustomerCode] ),'Table'[Segmentation] IN { "abc","cdf","opr" }
)
Ratio = DIVIDE ( [#RSP],DISTINCTCOUNT ( 'Table'[CustomerCode] ) )
,
您的数据中没有特定条件的客户:细分为“ abc”,“ cdf”和“ pqr”(任何行均与此不匹配)。您应该使用IN(也可以使用OR)
#RSP =
CALCULATE(DISTINCTCOUNT('Table'[CustomerCode]),FILTER(ALL('Table'),'Table'[Segmentation] in ("abc","opr")))
如果您要查找具有多个分段代码的行的客户:
#RSP_2 =
var __custSeg1 = filter('Table'[CustomerCode],TREATAS({"abc"},'Table'[Segmentation])
var __custSeg2 = filter('Table'[CustomerCode],TREATAS({"cdf"},TREATAS({"opr"},'Table'[Segmentation])
return
calculate(DISTINCTCOUNT('Table'[CustomerCode]),__custSeg1,__custSeg2,__custSeg2 )
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。