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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DivyaReddy
Frequent Visitor

RankX for multiple columns with percentage and numbers

Dear PBI enthusiasts!

I have a requirement where I need to show the Top N of a column '%Profit' and if there is a tie then I need to use the column 'Total Sales'. I am using RankX for my first column but not getting the second column to be used when there is a tie. 

Any help would be greatly appreciated and thank you in advance!

DivyaReddy_0-1666291860207.png

 

1 ACCEPTED SOLUTION

Hi @DivyaReddy ,

try this measure

Rank =

VAR Rank1 =

RANKX(ALL(Facts),

     [% Profit]

)

VAR Rank2 =

    VAR CurrentProfit = [% Profit]

    RETURN

    RANKX(

     CALCULATETABLE(

                   FILTER(

                         ADDCOLUMNS(

                                   Facts,

                                 "@Total Sales",[Total Sales],

                                 "@%Profit",[% Profit]

                                  ),

                        [% Profit] = CurrentProfit

                         ),

              ALL('Facts')),

[Total Sales]

)

RETURN

Rank1*Rank2

 

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

7 REPLIES 7
mangaus1111
Solution Sage
Solution Sage

Hi @DivyaReddy ,

 

try this calculated column:

 

RANK =
VAR _Rank =RANKX('Facts14',[%Profit])
RETURN
COUNTX(
       FILTER(
              'Facts14',
               'Facts14'[%Profit] = EARLIER('Facts14'[%Profit]) && 'Facts14'[Total Sales] > EARLIER('Facts14'[Total Sales])
             ),
       [Total Sales]
) + _Rank
 
Did I answer your question? Mark this post as a solution if I did!

 

This seems to have worked in theory but not sure why I get "Parameter not correct type" for "EARLIER('Facts14'[%Profit])" and EARLIER('Facts14'[Total Sales]) when I substituted my actual column and table names  They They are measures (not columns) in my actual data not sure if that matters?

Hi @DivyaReddy ,

try this measure

Rank =

VAR Rank1 =

RANKX(ALL(Facts),

     [% Profit]

)

VAR Rank2 =

    VAR CurrentProfit = [% Profit]

    RETURN

    RANKX(

     CALCULATETABLE(

                   FILTER(

                         ADDCOLUMNS(

                                   Facts,

                                 "@Total Sales",[Total Sales],

                                 "@%Profit",[% Profit]

                                  ),

                        [% Profit] = CurrentProfit

                         ),

              ALL('Facts')),

[Total Sales]

)

RETURN

Rank1*Rank2

 

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

Looking into it - thank u so much!

HI @DivyaReddy ,

Did I answer your question? Mark this post as a solution if I did!

mangaus1111
Solution Sage
Solution Sage

not very clear for me

Sorry abt that - updated the description and hopefully it is better now. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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