如何在DAX(Power BI Desktop)中计算总价值中的百分比

编程入门 行业动态 更新时间:2024-10-08 10:49:28
本文介绍了如何在DAX(Power BI Desktop)中计算总价值中的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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)中计算总价值中的百分比

本文发布于:2023-10-30 18:37:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543676.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:总价值   百分比   如何在   DAX   BI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!