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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
miketsilis
New Member

RANKX does not work with Percentage Ratio

Hello everyone,
I have a table with the following columns : KPI, Date and Value. Two of the KPIs are called Bonus Sales and another is Bonus Total and I did two measures accordingly. After I did a final one : Bonus Share = Bonus Sales/Bonus Total.
I want to highlight the Max and Min Values over a period of last 16 months in a line chart so I used the RANKX function :
Rank Desc Bonus Share =
RANKX(
           FILTER
           ( ALLSELECTED(Data),
           NOT(ISBLANK([Bonus Share])) ),
          [Bonus Share],
         , DESC, Dense )
The same for  Asc and finally I used a "highlighter as :
Highlight Max_Min Bonus Share =
IF([Rank Asc Bonus Share] = 1 || [Rank Desc Bonus Share] = 1, "Red", "#FFFFFF00").
As all the values are showing in the line chart (and not only the Max and Min), I did a simple table and I saw that next to each month and to Bonus Share I have only 1 or 2. For the Rank Desc Bonus Share I have only 1.
I did the same in another line chart where I have a sinlge Measure called Total Sales and it worked perfectly.
What could be the issue ?

Thank you very much for your time.

1 ACCEPTED SOLUTION
miketsilis
New Member

@AntrikshSharma I played around and it is working. 
Rank Desc Bonus Share =
RANKX(
           FILTER
           ( ALLSELECTED(Data[Date].[Date]),
           NOT(ISBLANK([Bonus Share])) ),
          [Bonus Share],
         , DESC, Dense )
That's the correct calculation. You were right about the aggregation on the Date level. The thing is that for my other graph it is working without that.
Thanks again for your time 🙂

View solution in original post

5 REPLIES 5
miketsilis
New Member

@AntrikshSharma I played around and it is working. 
Rank Desc Bonus Share =
RANKX(
           FILTER
           ( ALLSELECTED(Data[Date].[Date]),
           NOT(ISBLANK([Bonus Share])) ),
          [Bonus Share],
         , DESC, Dense )
That's the correct calculation. You were right about the aggregation on the Date level. The thing is that for my other graph it is working without that.
Thanks again for your time 🙂

@miketsilis Data[Date].[Date] - This is the wrong way of working with DAX you shouldn't use auto datetime tables, disable that in the options -> data load -> automatic date time and use a proper date table.

thanks for the advice and your time

miketsilis
New Member

@AntrikshSharma  thanks for your reply.
I tried what you proposed but it is not working unfortunately.
By the way the Bonus Share is a Measure out of the division of two other Measures, so it is not a column. 
I do not know why my calculation is working properly in another line chart which is using only one Measured called Total sales, but in that one where I show the ratio of Bonus Sales, it is not working properly.

AntrikshSharma
Super User
Super User

@miketsilis The column that you must be using for visual must have a lower granuarity than the whole table? Data table might have more unique combinations or must have a primary key? RANKX has to build a temporary table where it evaluates measure in row context and filter context so the granualrity of the visual should match the granularity inside the RANKX so you need to use ALLSELECTED ( Data[Column] ) construct.

 

Here is an example:

 

Year Rank RANKX ASC = 
RANKX ( 
    ALLSELECTED ( Dates[Year] ),
    [Total Sales], , 
    ASC
)
Year Rank RANKX DESC = 
RANKX ( 
    ALLSELECTED ( Dates[Year] ),
    [Total Sales], , 
    DESC
)

AntrikshSharma_0-1717935381254.png

 

Visual is using Year but if I change the ALLSELECTED ( Dates[Year] ) to ALLSELECTED ( Dates ) then the visual won't work as expected because Dates has a higher number of unique rows compared to Dates[Year].

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.