简体   繁体   English

Power BI 中具有动态条件的筛选表的测量结果意外

[英]Unexpected result of measure from filtering table with dynamic criteria in Power BI

I am very new to Power BI.我对 Power BI 很陌生。 Would you please to assist me to solve following issue:请您协助我解决以下问题:

I have a table called DW_XYZ:我有一个名为 DW_XYZ 的表:

Year|Month|Type|Value年|月|类型|值

2021|1|A|10 2021|1|A|10

2021|1|B|12 2021|1|B|12

2021|2|A|20 2021|2|A|20

*no data for type B in Month=2 *月份B类型无数据=2

I would like to create a measure that store data I already filtered by last month of data stored in DW_XYZ with dax formula:我想创建一个度量来存储我已经通过上个月存储在 DW_XYZ 中的数据过滤的数据,使用 dax 公式:

CALCULATE(SUM(DW_XYZ[Value]),FILTER(DW_XYZ,DW_XYZ[Month]=CALCULATE(MAX(DW_XYZ[Month]),FILTER(DW_XYZ,DW_XYZ[Year]=MAX(DW_XYZ[Year]))) && DW_XYZ[Year]=MAX(DW_XYZ[Year])) CALCULATE(SUM(DW_XYZ[Value]),FILTER(DW_XYZ,DW_XYZ[Month]=CALCULATE(MAX(DW_XYZ[Month]),FILTER(DW_XYZ,DW_XYZ[Year]=MAX(DW_XYZ[Year]))) && DW_XYZ[年]=MAX(DW_XYZ[年]))

From the measure, I create 2 card visuals to display data of Type A and Type B each.从度量中,我创建了 2 个卡片视觉效果来分别显示 A 类和 B 类的数据。 1st visual to display type A, so I drag the measure, and also drag column Type to 'visual filter' and manually select 'A', and do the same for 2nd visual (type B).第一个视觉显示类型 A,因此我拖动度量,并将列类型拖动到“视觉过滤器”并手动 select 'A',并对第二个视觉(类型 B)执行相同操作。

For type A, the card display expected value (of type A and Month=2).对于 A 类,卡片显示预期值(A 类和 Month=2)。 But for type B, the card display unexpected value (of type B and Month=1), it should be type B and Month=2 which is blank/zero.但是对于 B 类型,卡片显示意外值(B 类型且月份 = 1),它应该是 B 类型和月份 = 2,即空白/零。 **btw, would be highly appreciated if the formula including blank value-handling to be zero (0) instead of blank. **顺便说一句,如果包含空白值处理的公式为零 (0) 而不是空白,将不胜感激。

Try尝试

MyMeasure =
VAR MaxYear =
    CALCULATE ( MAX ( DW_XYZ[Year] ), ALL ( DW_XYZ[Type] ) )
VAR MaxMonth =
    CALCULATE ( MAX ( DW_XYZ[Month] ), ALL ( DW_XYZ[Type] ) )
RETURN
    0
        + CALCULATE (
            SUM ( DW_XYZ[Value] ),
            FILTER ( DW_XYZ, DW_XYZ[Year] = MaxYear && DW_XYZ[Month] = MaxMonth )
        )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM