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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Category fetching using RANK

We have a list of products and respective calculation. I need to fetch the top 3 categories on the basis of ranking of the products' calculation. Then create 3 separate graphs with top 3 products values, as given below:

 
Parul_0-1644215138755.jpeg
We need to make sure, if there are 3 products with 2nd rank, first 2 are picked.
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, I create a sample.

vkalyjmsft_0-1644573161405.png

Here's my solution. For example, your logic for sorting products is total sales.

1.Create a calculated column Rank.

Rank =
RANKX (
    ALL ( 'Table' ),
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Category] = EARLIER ( 'Table'[Category] ) ),
        'Table'[Sales]
    ),
    ,
    DESC,
    DENSE
)

Get the rank column.

vkalyjmsft_1-1644573377296.png

2.Put date and sales in a column chart, for the best selling, put Rank into the visual filter and select the value is 1.

vkalyjmsft_2-1644573443036.png

In the same way, for the 2nd most selling, select the visual filter to 2. For the 3rd most selling, select the visual filter to 3. Get the expected result.

vkalyjmsft_3-1644573675565.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, I create a sample.

vkalyjmsft_0-1644573161405.png

Here's my solution. For example, your logic for sorting products is total sales.

1.Create a calculated column Rank.

Rank =
RANKX (
    ALL ( 'Table' ),
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Category] = EARLIER ( 'Table'[Category] ) ),
        'Table'[Sales]
    ),
    ,
    DESC,
    DENSE
)

Get the rank column.

vkalyjmsft_1-1644573377296.png

2.Put date and sales in a column chart, for the best selling, put Rank into the visual filter and select the value is 1.

vkalyjmsft_2-1644573443036.png

In the same way, for the 2nd most selling, select the visual filter to 2. For the 3rd most selling, select the visual filter to 3. Get the expected result.

vkalyjmsft_3-1644573675565.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

@Anonymous , best is to use a visual level filter on the rank

 

Create a rank like this and then use filter

Rankx(allexcept(Table, Table[Product]),[sales],,desc,dense)

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

Power BI Monthly Update - August 2025

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