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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Top N nested

Hello everyone,

 

I am strugling to make a nested Top N.

 

The data I am currently working with is in a graph which looks like:

 

Product                             Divison                      SOH

A1711                               Car                               1259

A254                                  Van                              998

A2222                              Car                               18

A447                                  Van                              800

b2222                               Car                              13000

p888                                  Truck                         65413

k874                                  Van                             82

w841                                 Truck                        123

 

What I need is this to be ranked by SOH based by divison. Looking like the below

 

Product                             Divison                      SOH                          Rank

b2222                                Car                              13000                           1

A1711                               Car                               1259                             2

A2222                               Car                               18                                   3

A254                                  Van                              998                                1

A447                                  Van                              800                                2

k 874                                 Van                               82                                  3

p888                                  Truck                          65413                          1

w841                                 Truck                         123                                 2

 

Ideally I would need to be able to set the amount being shown within the graph and able to change on demand.

 

I am quite new to Power BI, so sorry if I am asking something simple.

 

Regards,

 

L

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, there are three ways o achieve your requirement.

 

Way1:

You may create a calculated column as follows.

 

 

RankColumn = 
COUNTROWS(
         FILTER(
             'Table',
             'Table'[Division] = EARLIER('Table'[Division])&&
             'Table'[SOH] > EARLIER('Table'[SOH])
         )
)+1

 

 

 

Result:

a1.png

 

Way2:

You may create a measure as below.

 

 

RankMeasure = 
RANKX(
    ALLSELECTED('Table'[Product]),
    CALCULATE(SUM('Table'[SOH])),
    ,
    DESC,
    Dense
)

 

 

 

Result:

a4.png

 

Way3:

You may create a calculated table as follows.

 

 

Table 3 = 
SUMMARIZE(
    'Table',
    'Table'[Product],
    'Table'[Division],
    'Table'[SOH],
    "rank",
    var _currentdivision = MAX('Table'[Division])
    var _currentsoh = MAX('Table'[SOH])
    return 
    COUNTROWS(
             FILTER(
                 ALL('Table'),
                 'Table'[Division] = _currentdivision&&
                 'Table'[SOH] > _currentsoh
             )
    )+1
)

 

 

 

Result:

a3.png

 

Best Regards

Allan

 

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
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.

 

Best Regards

Allan

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, there are three ways o achieve your requirement.

 

Way1:

You may create a calculated column as follows.

 

 

RankColumn = 
COUNTROWS(
         FILTER(
             'Table',
             'Table'[Division] = EARLIER('Table'[Division])&&
             'Table'[SOH] > EARLIER('Table'[SOH])
         )
)+1

 

 

 

Result:

a1.png

 

Way2:

You may create a measure as below.

 

 

RankMeasure = 
RANKX(
    ALLSELECTED('Table'[Product]),
    CALCULATE(SUM('Table'[SOH])),
    ,
    DESC,
    Dense
)

 

 

 

Result:

a4.png

 

Way3:

You may create a calculated table as follows.

 

 

Table 3 = 
SUMMARIZE(
    'Table',
    'Table'[Product],
    'Table'[Division],
    'Table'[SOH],
    "rank",
    var _currentdivision = MAX('Table'[Division])
    var _currentsoh = MAX('Table'[SOH])
    return 
    COUNTROWS(
             FILTER(
                 ALL('Table'),
                 'Table'[Division] = _currentdivision&&
                 'Table'[SOH] > _currentsoh
             )
    )+1
)

 

 

 

Result:

a3.png

 

Best Regards

Allan

 

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

amitchandak
Super User
Super User

Please this article

https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

 

RANKX(all('Item'[Product]),[SOH],,DESC,Dense) 
RANKX(all('Item'[Product]),calculate(sum([SOH])),,DESC,Dense) 

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.