Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
svenvu
Advocate I
Advocate I

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

 

 

Rank.png

 

 

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:

Rank2.png

 

 

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

 

Friendly greets

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

 

What result do you get with this?

 

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


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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

 

Hi,

 

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


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi

 

You can download the pbix file from the link below:

Testfile PBIX

 

 

I need the measure "Rank" to rank the "Subcategorie" according to the measure "Verschil t.o.v. j-1".

This measure needs to work with filters from 4 different tables as you can see in the screenshot below.

But the tricky part is that I can not have gaps between the rank numbers and at this moment this is the case.

 

As you can see in the screenshot below the ranking works fine, but ranknumber 10 needs to be number 5 and ranknumber 11 needs to be number 6.

 

 

 

afbeelding.png

 

 

What I have already found out is that the DAX-formula I have used in the measure "Rank" works with almost every other measure. For example "Budget": no gaps in the ranknumbers:

 

afbeelding.png

 

I think the gaps are created because of this measure:

% Verschil t.o.v. j-1 = 
[% Aangerekend] - [% Aangerekend j-1]


% Aangerekend =
DIVIDE (
    CALCULATE (
        SUM ( Measuretable[Aangerekend] );
        FILTER ( ALL ( Datum[Kwartaal] ); Datum[Kwartaal] <= MAX ( Datum[Kwartaal] ) )
    );
    [Budget]
)

% Aangerekend j-1 =
DIVIDE (
    CALCULATE (
        SUM ( Measuretable[Aangerekend] );
        PREVIOUSYEAR ( Datum[Datum] );
        FILTER ( ALL ( Datum[Kwartaal] ); Datum[kwartaal] <= MAX ( Datum[Kwartaal] ) )
    );
    CALCULATE (
        [Budget];
        PREVIOUSYEAR ( Datum[Datum] )
    )
)

If I change the sign "-" into "*", the measure "Rank" works without showing any gaps in the ranknumber.

But ofcourse the output is not what I want as I want to use the sign "-". It's like DAX calculates 2 times and therefore creates 12 possible rankingnumbers instead of 6.

 

It would be extremely awesome if this could be fixed. I refuse to believe that it works for almost every measure except the one I need.

 

Friendly greets

 

 

 

Hi,

 

I tried but could not solve the problem.  Sorry.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur or anyone else who knows RankX

 

I did some troubleshooting myself and I think I might know the source of the problem. For the positive numbers the ranking works great but as soon as there are negative numbers the RankX creates a gap between the ranknumbers

 

Does this help to find a solution?

 

Friendly greets

Helpful resources

Announcements
Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.