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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors