简体   繁体   中英

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

I am very new to Power BI. Would you please to assist me to solve following issue:

I have a table called DW_XYZ:

Year|Month|Type|Value

2021|1|A|10

2021|1|B|12

2021|2|A|20

*no data for type B in Month=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:

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]))

From the measure, I create 2 card visuals to display data of Type A and Type B each. 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).

For type A, the card display expected value (of type A and 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. **btw, would be highly appreciated if the formula including blank value-handling to be zero (0) instead of blank.

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 )
        )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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