Forum Discussion

ruxandraalina's avatar
3 years ago
Solved

Dynamic ranking based on filter context

Hello,  I've been struggling to create a ranking that shows the county with the highest/lowest value based on my filter context, as shown below:   I need to create two cards that show (1) th...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi ruxandraalina ,

    Please try to create two measure with below dax formula:

    Highest Value =
    VAR _year =
        SELECTEDVALUE ( 'Table'[Year] )
    VAR _str =
        CONCATENATEX ( 'Table', [Category] )
    VAR tmp =
        FILTER (
            ALL ( 'Table' ),
            [Year] = _year
                && CONTAINSSTRING ( _str, [Category] )
        )
    VAR _max =
        MAXX ( tmp, [Value] )
    VAR _val =
        CALCULATE ( MAX ( 'Table'[Country] ), FILTER ( tmp, [Value] = _max ) )
    RETURN
        _val
    
    Lowest Value =
    VAR _year =
        SELECTEDVALUE ( 'Table'[Year] )
    VAR _str =
        CONCATENATEX ( 'Table', [Category] )
    VAR tmp =
        FILTER (
            ALL ( 'Table' ),
            [Year] = _year
                && CONTAINSSTRING ( _str, [Category] )
        )
    VAR _min =
        MINX ( tmp, [Value] )
    VAR _val =
        CALCULATE ( MAX ( 'Table'[Country] ), FILTER ( tmp, [Value] = _min ) )
    RETURN
        _val
    

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.