问题描述
我在Power BI Desktop中具有以下切片器,其中#个客户端在我的数据模型中计算为 Count(Distinct(Fact.EHRTransaction.ClientFK)):
I have the following Slicer in Power BI Desktop, where # of Clients is calculated as Count(Distinct(Fact.EHRTransaction.ClientFK)) in my data model:
我的目标是计算总计的百分比(13639),并将其作为度量或另一列添加到此切片器中,例如:
My goal is to calculate Percentage out of Total (13 639) and add it to this slicer as a Measure or another Column, like:
Gender # of Clients Total Clients
Unknown 2 0.00%
Intersex 13 0.00%
Transgender 18 0.00%
Female 662 0.04%
Male 832 0.05%
(Not Recorded) 12 112 72.79%
我尝试添加以下列:
Percentage = 'FactEHRClinicalTransaction'[ClientFK]/
CALCULATE(SUM('FactEHRClinicalTransaction'[ClientFK]),ALLSELECTED())
但是我得到的值不正确-
But I am getting an incorrect values -
请帮忙或咨询!
更新:最后,找到了解决方案:为了实现这些计算,需要为每个操作添加措施.然后,在最终的%计算中使用它们(而不是字段)-
Update:Finally, found a solution:In order to achieve these calculations, needed to add a Measures for each operation. And then, use them (not the fields) in final % calculation -
# of Clients = DISTINCTCOUNT('Fact EHRClinicalTransaction'[ClientFK])
# of Clients_Total =
CALCULATE(DISTINCTCOUNT('Fact EHRClinicalTransaction'[ClientFK]),
ALLSELECTED('Fact EHRClinicalTransaction'))
% of Clients = DIVIDE('Fact EHRClinicalTransaction'
[# of Clients],'Fact EHRClinicalTransaction'[# of Clients_Total])
推荐答案
您似乎在该部门的第一部分中缺少汇总,而在第二部分中对FK求和而不是进行计数.试试这个:
It looks like you are missing an aggregation in the first part of your division and are summing the FKs in the second part instead of counting. Try this:
Percentage =
DIVIDE (
DISTINCTCOUNT ( 'FactEHRClinicalTransaction'[ClientFK] ),
CALCULATE (
DISTINCTCOUNT ( 'FactEHRClinicalTransaction'[ClientFK] ),
ALLSELECTED ()
)
)
使用DIVIDE()可进行更安全的划分.
Using DIVIDE() makes for a safer division.
这篇关于如何在DAX(Power BI Desktop)中计算总价值中的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!