Forum Discussion

svenvu's avatar
svenvu
Advocate I
7 years ago

Dynamic Ranknumber

Hi

 

I have 6 categories, 20 subcategories and 1 measure.

I want to rank the subcategories and the ranking works fine but when I filter on a categorie there's a gap in the ranking. I need 10 to be rank number 5 and 11 to be rank number 6. Is there some way to achieve this? Changing the datamodel, changing the dax formula?

 

My datamodel has:

  • a datedimension which is filtered by year and quarter
  • a measuredimension which is filtered by subcategorie

 

 

 

 

The rankmeasure I used:

Rank =
RANKX (
    ALLSELECTED ( Measuretable[Subcategorie] );
    SUM ( Measuretable[Budget] )
)

 

 

I also tried this formula:

Rank =
RANKX (
    ALLSELECTED ( Measuretable[Subcategorie] );
    CALCULATE (
        SUM ( Measuretable[Budget] );
        ALLEXCEPT ( Measuretable; Measuretable[Subcategorie] )
    )
)

 

but still got a gap:

 

 

Many thanks for anyone who can put me in the right direction!

 

Friendly greets

6 Replies

  • Hi,

     

    What result do you get with this?

     

    Rank =RANKX(ALL(Measuretable[Subcategorie]);SUM(Measuretable[Budget]))

    • svenvu's avatar
      svenvu
      Advocate I

      Hi

       

      It doesn't make a difference in the result. I simplified the example. Actually the measure isn't the "budget" but a more complex measure:

       ([% spend this year] - [% spend previous year]) * [Budget]

       

      The strange thing is: the Rank measure works perfectly with each individual measure. However it does not work anymore with the part "% spend this year"-"%spend previous year".

       

      This part is written in dax as follows:

       

      DIVIDE (
          CALCULATE (
              SUM ( Measuretable[Spend] );
              FILTER ( ALL ( Date[Quarter] ); Date[Quarter] <= MAX ( Date[Quarter] ) )
          );
          [Budget]
      )
      
      -
      
      DIVIDE (
          CALCULATE (
              SUM ( Measuretable[Spend] );
              FILTER ( ALL ( Date[Quarter] ); Date[Quarter] <= MAX ( Date[Quarter] ) )
          );
          [Budget]
      )

      So RANKX must do something with this part that creates more ranknumbers with gaps in it.

      That is the real life problem that I can't fix.

       

      Any help is much appreciated! :)

       

      Friendly greets

       

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

         

        I am still not clear with your question.  If you could share the raw dataset and describe the question, it would be great.