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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Jlbaenlo
Frequent Visitor

Ranking a combination of attributes based on a measure...

Dear Community,

I'm looking for some help on Ranking expression...

 

In PowerBI, have a table
-Product, which contains the fields prdid, brand (1 Brand can contain several Prdid)
-Country, which contains the field country
a measure : m which I want to display at Brand - Country (which depends of other slicers on the visual)
I want to rank the Brand Country combination based on this measure m - which DAX formula should I use for Rankx

I cannot create a calculated table with Brand, Country and m as m depends on other slicers

so I wanted to use a virtual table VAR like

VAR Brand_Country_Combi = summarizecolumns(Product[Brand],Country[country], "mymeasure",[m])

and then use

RANKX(ALL( Brand_Country_Combi), [m],,DESC,DENSE)

but it does not work as ALL can only apply to real table not expression.

Any idea on how to overcome this ?

 

Many thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from lbendlin and johnt75, please allow me to provide another insight.
Hi @Jlbaenlo ,

I am not sure how your data model is designed, here is my sample.

The data model is as follows.

vdengllimsft_0-1736490135081.png


The m measure is used to calculate the number of products.

Use the following measurements to calculate the ranking.

RANK = 
VAR _tb =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZECOLUMNS ( 'Product'[Brand], 'Country'[Country] ),
            "mymeasure", [m]
        ),
        ALL ()
    )
RETURN
    RANKX ( _tb, [m],, DESC, DENSE )

 

The final result is as follows.

vdengllimsft_1-1736491208995.png

 

Please see the pbix for reference.

Best Regards,
Dengliang Li

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

3 REPLIES 3
Anonymous
Not applicable

Thanks for the reply from lbendlin and johnt75, please allow me to provide another insight.
Hi @Jlbaenlo ,

I am not sure how your data model is designed, here is my sample.

The data model is as follows.

vdengllimsft_0-1736490135081.png


The m measure is used to calculate the number of products.

Use the following measurements to calculate the ranking.

RANK = 
VAR _tb =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZECOLUMNS ( 'Product'[Brand], 'Country'[Country] ),
            "mymeasure", [m]
        ),
        ALL ()
    )
RETURN
    RANKX ( _tb, [m],, DESC, DENSE )

 

The final result is as follows.

vdengllimsft_1-1736491208995.png

 

Please see the pbix for reference.

Best Regards,
Dengliang Li

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

johnt75
Super User
Super User

Try

Ranking =
VAR TableToRank =
    ADDCOLUMNS (
        SUMMARIZE ( 'Product', 'Product'[Brand], Country[Country] ),
        "@m", [m]
    )
VAR Result =
    RANK ( TableToRank, ORDERBY ( [@m], DESC ) )
RETURN
    Result
lbendlin
Super User
Super User


You cannot measure a measure directly. Either materialize it first, or create a separate measure that implements the entire business logic.

 

Use of RANKX in Power BI measures - SQLBI

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors