Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

RANKX issue

i am trying to do a ranking by total and by months but for some reaosn when i am doing the ranking i am geting rankings for months that havent even happened please see below;

 

 

 

 

 

 

  • Hi Anonymous ,

     

    Please create measures like this.

    Measure = 
    CALCULATE(
        SUM(Sales[Sale 2014]),
        FILTER(
            ALL(Sales),
            Sales[Month] = MAX(Sales[Month]) && Sales[CountryRegion] = MAX(Sales[CountryRegion])
        )
    )
    Measure 2 = 
    VAR x =  
    RANKX(
        FILTER( ALLSELECTED(Sales), Sales[Month] = MAX(Sales[Month]) ),
        [Measure],
        , ASC, Dense
    )
    VAR y =  
    RANKX(
        FILTER( ALLSELECTED(Sales), Sales[CountryRegion] = MAX(Sales[CountryRegion]) ),
        [Measure],
        , ASC, Dense
    )
    RETURN
    IF(
        HASONEFILTER(Sales[CountryRegion]),
        x, y
    )

     

    Best regards,
    Lionel Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

11 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous ,

     

    Try measure like

     

    Measure = IF ([Total] <> BLANK() , RANKX ......  ))

     

    Also, if you can share sample data.

     

    For Ranks pls refer these articles

     

    https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
    https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
    https://databear.com/how-to-use-the-dax-rankx-function-in-power-bi/

     

     

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

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    You can try to use the below measure to do the rank:

     

    Measure = RANKX(filter(all(month),your_rank_measure > 0),your_rank_measure,,desc)

     

    Please try.

     

    If it's not what you want, please show some sample data and your data model.

     

    Thanks.

    Aiolos Zhao 

  • v-lionel-msft's avatar
    v-lionel-msft
    Community Support

    Hi Anonymous ,

     

    Like this?

    Measure = 
    CALCULATE(
        SUM(Sales[Sale 2014]),
        FILTER(
            ALL(Sales),
            Sales[Month] = MAX(Sales[Month])&& Sales[CountryRegion] = MAX(Sales[CountryRegion])
        )
    )
    Measure 2 = 
    RANKX(
        FILTER( ALLSELECTED(Sales), Sales[CountryRegion] = MAX(Sales[CountryRegion]) ),
        [Measure],
        , ASC, Dense
    )

    Or like this?

    Measure 3 = 
    CALCULATE(
        SUM(Sales[Sale 2014]),
        FILTER(
            ALL(Sales),
            Sales[Month] = MAX(Sales[Month])
        )
    )
    Measure 4 = 
    RANKX(
        FILTER( ALLSELECTED(Sales),Sales[CountryRegion] = MAX(Sales[CountryRegion]) ),
        [Measure 3],
        , ASC, Dense
    )

     

    Best regards,
    Lionel Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      v-lionel-msft thank you for this, so the way i am looking to do it, is if you added your country to sit below the month on the left of matrix, you would have your ranking by month but whne you open up the month it then will give you the ranking for the countries in that month so based on the 4 countries it would rank them 1 to 4 then if i was to drill into the the country i could then get more infornation etc

       

      • v-lionel-msft's avatar
        v-lionel-msft
        Community Support

        Hi Anonymous ,

         

        Please create measures like this.

        Measure = 
        CALCULATE(
            SUM(Sales[Sale 2014]),
            FILTER(
                ALL(Sales),
                Sales[Month] = MAX(Sales[Month]) && Sales[CountryRegion] = MAX(Sales[CountryRegion])
            )
        )
        Measure 2 = 
        VAR x =  
        RANKX(
            FILTER( ALLSELECTED(Sales), Sales[Month] = MAX(Sales[Month]) ),
            [Measure],
            , ASC, Dense
        )
        VAR y =  
        RANKX(
            FILTER( ALLSELECTED(Sales), Sales[CountryRegion] = MAX(Sales[CountryRegion]) ),
            [Measure],
            , ASC, Dense
        )
        RETURN
        IF(
            HASONEFILTER(Sales[CountryRegion]),
            x, y
        )

         

        Best regards,
        Lionel Chen

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.