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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Tlotly
Resolver II
Resolver II

Ranking a rank measure returns 1

Good day 

 

Why does the following measure returns 1 for all rows? I'm basically trying to rank branches on two measures.

 

new_rank_par_01 = var _rank1 =  RANKX (
               ALLSELECTED ('Centre details' ),
               CALCULATE( [sumPO], ALLEXCEPT('Centre details','Centre details'[Branch Description]))
           ,,DESC,dense )  
  +
 
            RANKX (
               ALLSELECTED ('Centre details' ),
               CALCULATE( [PAR %], ALLEXCEPT('Centre details','Centre details'[Branch Description]))
               
           ,,ASC,dense )
       *1000
RETURN
RANKX ( ALL('Centre details'[Branch Description]), _rank1
           ,,ASC,dense )
 
Thanks in advance,
M

(Make it a data day!)

1 ACCEPTED SOLUTION

Hi @Tlotly 

 

Thank you for sharing!

 

As you describe: the branch code with the highest outstanding principal should be first.

PO_rank = 
            RANKX ( 
                ALLSELECTED (Sheet1[Branch Code] ) ,
               CALCULATE(SUM('Sheet1'[Principal Outstanding]), ALLEXCEPT(Sheet1,Sheet1[Branch Code]))
           ,,DESC,dense ) 

 

vnuocmsft_0-1716540422573.png

 

new_rank_par_01 = 
RANKX(ALL('Sheet1'), [PO_rank] + [PAR_rank] * 1000,,DESC,Dense)

 

vnuocmsft_1-1716540519149.png

 

After the code is merged, it is as follows:

 

Measure new_rank_par_01 = 
var PAR_rank = 
            RANKX ( 
                ALLSELECTED (Sheet1[Branch Code] ) ,
               CALCULATE([PAR %], ALLEXCEPT(Sheet1,Sheet1[Branch Code]))
           ,,ASC,dense ) 
var PO_rank = 
            RANKX ( 
                ALLSELECTED (Sheet1[Branch Code] ) ,
               CALCULATE(SUM('Sheet1'[Principal Outstanding]), ALLEXCEPT(Sheet1,Sheet1[Branch Code]))
           ,,DESC,dense ) 

RETURN RANKX(ALL('Sheet1'), [PO_rank] + [PAR_rank] * 1000,,DESC,Dense)

 

vnuocmsft_2-1716540617294.png

 

Regards,

Nono Chen

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

View solution in original post

4 REPLIES 4
v-nuoc-msft
Community Support
Community Support

Hi @Tlotly 

 

I speculate that there could be a filtering issue.

 

You could simplify the code to make it easier to better check that the results in each section match.

 

To better help you solve your problem, please provide some dummy data, preferably in tabular form.

 

Regards,

Nono Chen

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

@v-nuoc-msft 

 

I did simplify the code. And I've atatched the sample report on the link below.

So to break the tie, I wanted to use Principal Outstanding i.e. a branch code with the highest principal outstanding should be ranked first.

 

https://www.dropbox.com/scl/fi/u03iwulit1a39zafpoifc/Rank_test.pbix?rlkey=tcumz6p2hhlflhobyag6fj9sr&...

 

 

 

Thank you in advance.

Hi @Tlotly 

 

Thank you for sharing!

 

As you describe: the branch code with the highest outstanding principal should be first.

PO_rank = 
            RANKX ( 
                ALLSELECTED (Sheet1[Branch Code] ) ,
               CALCULATE(SUM('Sheet1'[Principal Outstanding]), ALLEXCEPT(Sheet1,Sheet1[Branch Code]))
           ,,DESC,dense ) 

 

vnuocmsft_0-1716540422573.png

 

new_rank_par_01 = 
RANKX(ALL('Sheet1'), [PO_rank] + [PAR_rank] * 1000,,DESC,Dense)

 

vnuocmsft_1-1716540519149.png

 

After the code is merged, it is as follows:

 

Measure new_rank_par_01 = 
var PAR_rank = 
            RANKX ( 
                ALLSELECTED (Sheet1[Branch Code] ) ,
               CALCULATE([PAR %], ALLEXCEPT(Sheet1,Sheet1[Branch Code]))
           ,,ASC,dense ) 
var PO_rank = 
            RANKX ( 
                ALLSELECTED (Sheet1[Branch Code] ) ,
               CALCULATE(SUM('Sheet1'[Principal Outstanding]), ALLEXCEPT(Sheet1,Sheet1[Branch Code]))
           ,,DESC,dense ) 

RETURN RANKX(ALL('Sheet1'), [PO_rank] + [PAR_rank] * 1000,,DESC,Dense)

 

vnuocmsft_2-1716540617294.png

 

Regards,

Nono Chen

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

@v-nuoc-msft  Thank you very much. It's working perfectly now. I only changed the sorting order in the return measure to ASC since PAR takes precedence. Sorry for not making it clear in my initial response.

 

Tlotly,

Make it a data day!

Tlotly_0-1716544634156.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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