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 field >0 is applying on all the months, BUT, I want it to apply only on latest MAR month.

 

As such Name "F" should filter out per my result. How can i get this. Please help.

 

NameMAR FEBJAN
A181416
B212213
C11716
D1922-12
E10-7-11
F-111016
G147

 

 

  • 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

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous ,

     

    Create a visual filter

     

     

    Regards,
    Harsh Nathani
    Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Anonymous - Is that really how your data looks? Thinking you should unpivot those month columns.

  • Hi Anonymous ,

     

    Consider following sample data:

    Create a caluclated column as follows:

    newCol = CALCULATE(SUM(DaxCalc[Mar]), DaxCalc[Mar] > 0)
     
    Move this to your table visual, you get following output:
     
     
    Thanks,
    Pragati
  • Anonymous's avatar
    Anonymous
    Not applicable

    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