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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

First time I am going to use the ranks function and need help

Hello, I want to use the Rankx function to evaluate the ten best employees, depending on the number of transactions 
processed. This ranking will vary due to the use of filters/Slicers (ex: selection of the province, business line etc.) Since I have never used the rankx function, I did a search on the web and read the article at the following address:
https://www.sqlbi.com/articles/use-of-rankx-in-power-bi-measures/ To be honest, I did not understand all the subtleties and differences of the scripts.
I don't understand the difference between the following scripts and what we are going to obtain

[Rank Name Simple] :=
IF (
    HASONEVALUE ( Test[Name] ),
    RANKX ( ALL ( Test[Name] ), [Sum Value] )
)
My interpretation of the above script is: if test[Name] has a value, then rank all the name based on the [ sum value].  
If I am wrong, please let me know.

For the script below, I don't understand why we add the test[value] in the function, and how this will affect the result
Feel free to explain how adding test[value] will impact the results

[Rank Name] :=
IF (
    HASONEVALUE ( Test[Name] ),
    RANKX ( ALL ( Test[Name], Test[Value] ), [Sum Value] )
)


That's why I'm asking for help from the community.
I just want to make sure that when I apply a filter/slicer, I will get the right results.

Imagine that I have a table with Name, Region, Business line , employeeName and the number of transactions treated
by thoses employees.

Those employees are associated to some business line, not all and are also associated to a geographic region
(ex: western region, or Atlantic region and so on).

Therefore, the produced table content will vary due to the use of filter on region and business line and other filters.
Depending on those results, I would like to produce another table which show the top 10 employees based on the number of
transactions.

So, as I have never used the rankx function before, I can I make sure that the top 10 list will be good considering the
applied filters.

Does someone could give me an example of the proper use of the rankx function with let's say the use of two filters
the region, and business line based on the number of transactions.

Thank you in advance for your help
alepage

 

2 REPLIES 2
kcantor
Community Champion
Community Champion

@Anonymous 

Your interpretation of HASONEVALUE is slightly off. In fact, it is asking if the field has one value. My salesperson table has one value at the employee name but, as an example, multiple names in the region. Therefore, it would work as long as the employee name is the top in any of your drill downs or filters.  In other words, if you put region above the rep name, the rank would be incorrect for the region. That doesn't mean that you cannot write the calculation to account for multiple levels, you can, but it would be irrelevant for this question.  Your other slicers and filters would be respected withint the count of transactions calculation you would need.

 

You would need something along the lines of:

Rank = IF(

                 ISFILTERED('RepTable'[Name]),

                 RANKX(

                 ALLSelected ('RepTable'[Name]),

                 [Count of Transactions], , DESC, Dense

                 )

)

This would rank the reps by name using a measure called Count of Transactions (you would need to define and create), in descending order, populating the rank in a dense fashion to use as many numbers as possible. Don't skip the comma space comma!

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks a lot for your anwser.

 

Here's the script I am testing and it seems to work well.  Feel free to make any comment or warning.  As I have mentioned , it is the first time I am using the rankx function.

 

The amout is in a fact table  which is affected by the slicer.  So, I am using the measure below

 

Sum Amount = sum('Fact Labor'[ProjCost])
 
The biller name is in a dim table.  Here's the script, I am testing:
 
Rank = IF(
                NOT ISBLANK([Sum Amount]),
                 RANKX(
                 ALLSelected ('Dim Biller'[FullName]),
                 [Sum Amount], , DESC, Dense
                 )
)
 
The rank is attributed to the biller (from a dim table),
based on the Sum Amount (from a fact table).
 
Is it correct to do that?
 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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