Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Dax calc help

Hello All,   I want help in formulating DAX for my use case. Sample data is below. I want to show/FILTER only those rows whose latest month (MAR) value is >0. Creating a if statement on the value...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Anonymous,

    According to your description, your table seems to contain multiple month fields with values and you are try to filter on them to hide the last month records that than less than zero?

    If this is a case, I'd like to suggest you do unpivot columns on your month fields to convert them to attitude and value fields.

    Unpivot columns (Power Query) 

    Then you can write a measure formula and use on 'visual level filter' to filter last month records.

    Applying a measure filter in Power BI 

    measure =
    VAR list =
        ADDCOLUMNS (
            VALUES ( Table[Attribute] ),
            "Date", DATEVALUE ( [Attribute] & "/1" )
        )
    VAR _lastMonth =
        MAXX ( list, [Date] )
    VAR currValue =
        CALCULATE (
            SUM ( Table[Value] ),
            FILTER ( ALLSELECTED ( Table ), [Attribute] = FORMAT ( _lastMonth, "MMM" ) ),
            VALUES ( Table[Name] )
        )
    RETURN
        IF (
            SELECTEDVALUE ( Table[Attribute] ) = FORMAT ( _lastMonth, "MMM" )
                && currValue > 0,
            "Y",
            "N"
        )
    

    Regards,

    Xiaoxin Sheng