对PowerBI和DAX中缺少数据的度量进行平均

DJA

我试图绕过DAX奋斗。我有一个PowerBI矩阵,我需要在其中计算度量的平均值。该度量是“人口百分比”,从表面上看,它似乎完全符合预期。

它在两个级别的顶部矩阵中正确计算,并且在底部表格中正确汇总。

例如,我以红色突出显示了“ A3”的计算顺序

具有完整数据的PowerBI

为了记录,人口百分比设置为

% of Population = sum(Data[Value])/sum('Level'[Population])

当我在“国家/地区”上进行过滤并仅选择“国家2”时会出现问题

缺少数据的PowerBY

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.

Alexis Olson

发生这种情况的原因是,该Country表不会Level在关系图中过滤该表,因为它们都只过滤到该Data表的一种方式,并且没有其他关系。

在不更改数据模型的情况下,在DAX中解决此问题的一种方法是指定您只想计算当前过滤器上下文PopulationLevel[LevelId]与匹配的位置Data[SecondLevelId]

Population =
DIVIDE (
    SUM ( Data[Value] ),
    CALCULATE (
        SUM ( 'Level'[Population] ),
        'Level'[LevelId] IN VALUES ( Data[SecondLevelId] )
    )
)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章