Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Filter matrix based on margin performance

Hi, I have a problem with the matrix filter issue. Now I have a matrix table looks like this: ItemNo\Margin\Date week 1 week2 1 1 1 2 1 0.5 3 1 1.5 the original data tab...
  • v-deddai1-msft's avatar
    v-deddai1-msft
    6 years ago

    Hi Anonymous,

     

    I suggest you use the following dax to create a calculated column to rank the temNo:

     

    rank =
    
    CALCULATE (
    
        COUNTROWS ( 'Table' ),
    
        FILTER (
    
            ALL ( 'Table' ),
    
            'Table'[tem No] = EARLIER ( 'Table'[tem No] )
    
                && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
    
        )
    
    )

     

    Then use the following dax to created the filter column:

     

    Column 2 =
    
    VAR b = 'Table'[Margin]
    
    VAR a =
    
        CALCULATE (
    
            MAX ( 'Table'[Margin] ),
    
            FILTER (
    
                ALL ( 'Table' ),
    
                'Table'[tem No] = EARLIER ( 'Table'[tem No] )
    
                    && 'Table'[rank]
    
                        = EARLIER ( 'Table'[rank] ) - 1
    
            )
    
        )
    
    VAR c =
    
        CALCULATE (
    
            MAX ( 'Table'[Margin] ),
    
            FILTER (
    
                ALL ( 'Table' ),
    
                'Table'[tem No] = EARLIER ( 'Table'[tem No] )
    
                    && 'Table'[rank]
    
                        = EARLIER ( 'Table'[rank] ) + 1
    
            )
    
        )
    
    RETURN
    
        IF (
    
            'Table'[rank] = 1,
    
            SWITCH ( TRUE (), b > c, "decrease", b < c, "increase", BLANK () ),
    
            SWITCH ( TRUE (), b < a, "decrease", b > a, "increase", BLANK () )
    
        )

     

    For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EU2VJv_n_n9PpDgia5AoYmYBcJOEMmtSudf5fMKybWzpgQ?e=CVHJel

     

     

    Best Regards,

    Dedmon Dai