我试图绕过DAX奋斗。我有一个PowerBI矩阵,我需要在其中计算度量的平均值。该度量是“人口百分比”,从表面上看,它似乎完全符合预期。
它在两个级别的顶部矩阵中正确计算,并且在底部表格中正确汇总。
例如,我以红色突出显示了“ A3”的计算顺序
为了记录,人口百分比设置为
% of Population = sum(Data[Value])/sum('Level'[Population])
当我在“国家/地区”上进行过滤并仅选择“国家2”时会出现问题
Country 2 does not have data for "D13". Although the Values sum up correctly (170), the Sum of the Population includes the 300 from the missing D13 row making a total of 600 and the '% population' of 28.33% (instead of 170 / 300 = 57%)
I am happy to turn off the group totals in the top grid so that the 28.33 does not show; so my real problem is actually with the bottom grid.
I think I need a new measure to be displayed in the bottom grid. I think it simply needs to sum up the values and divide by the sum of the populations - but only when the value is present. How do I do that?
Or am I totally on the wrong track and there is an obvious answer that I am missing?
The PowerBI file can be downloaded from here
Thanks in advance.
发生这种情况的原因是,该Country
表不会Level
在关系图中过滤该表,因为它们都只过滤到该Data
表的一种方式,并且没有其他关系。
在不更改数据模型的情况下,在DAX中解决此问题的一种方法是指定您只想计算当前过滤器上下文Population
中Level[LevelId]
与匹配的位置Data[SecondLevelId]
。
Population =
DIVIDE (
SUM ( Data[Value] ),
CALCULATE (
SUM ( 'Level'[Population] ),
'Level'[LevelId] IN VALUES ( Data[SecondLevelId] )
)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句