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
andrew_tran
Frequent Visitor

How to rank such that the original rank remains when individual items are selected

Hi all,

 

I have been able to rank the data as follows. However, when I select an item individually, the rank changes. Is there a DAX solution such that the rank remains the same?

 

For example, item A4 has the rank of 4, which is as expected

andrew_tran_0-1738761492203.png

 

However, when I select item A4 individually using the Name filter, the rank changes to 1, and I expect it to continue to be 4

andrew_tran_2-1738761728620.png

 

Below is the formula used for the measure RANK_DESC:

RANK_DESC = RANKX(ALLSELECTED('Table'[SKU ID]),[SUM],,DESC,Dense)
 

Below is the formula used for the measure SUM:

SUM = SUM('Table'[Value])
 
This is what the underlying table looks like:
andrew_tran_1-1738761653248.png

 

I have also tried to attach the underlying pbix file but was not able to do so, so my apologies. Because of this, please find instead below the raw data of the only table used in the pbix file.

 

DateCategoryCountrySKU IDNameValue
1-Jan-24AUSAA1A1220
2-Jan-24AUSAA1A1366
3-Jan-24AUSAA1A1169
4-Jan-24AUSAA1A1366
5-Jan-24AUSAA1A1531
6-Jan-24AUSAA1A1587
1-Jan-24AUKA2A2893
2-Jan-24AUKA2A2866
3-Jan-24AUKA2A268
4-Jan-24AUKA2A2756
5-Jan-24AUKA2A2587
6-Jan-24AUKA2A2653
1-Jan-24BUSAA3A338
2-Jan-24BUSAA3A3798
3-Jan-24BUSAA3A3919
4-Jan-24BUSAA3A3634
5-Jan-24BUSAA3A3599
6-Jan-24BUSAA3A3564
1-Jan-24BUKA4A4521
2-Jan-24BUKA4A4648
3-Jan-24BUKA4A4405
4-Jan-24BUKA4A4132
5-Jan-24BUKA4A4751
6-Jan-24BUKA4A4474
1-Jan-24CUSAA5A5525
2-Jan-24CUSAA5A5659
3-Jan-24CUSAA5A5986
4-Jan-24CUSAA5A5354
5-Jan-24CUSAA5A5118
6-Jan-24CUSAA5A5481
1-Jan-24CUKA6A6252
2-Jan-24CUKA6A630
3-Jan-24CUKA6A6795
4-Jan-24CUKA6A6342
5-Jan-24CUKA6A6221
6-Jan-24CUKA6A659

 

 Could any expert help to advise? Thank you so much!!

1 ACCEPTED SOLUTION
andrew_tran
Frequent Visitor

However, I just realized that upon changing the formula from:

RANK_DESC = RANKX(ALLSELECTED('Table'[SKU ID]),[SUM],,DESC,Dense)

to:

RANK_DESC = RANKX(ALL('Table'[SKU ID],'Table'[Name]),[SUM],,DESC,Dense)

the formula then gave me the result I wanted

andrew_tran_0-1738764596289.png

Thanks a lot for providing the tip!

View solution in original post

5 REPLIES 5
johnt75
Super User
Super User

You can use

Rank Desc = 
VAR BaseTable =
    CALCULATETABLE (
        SUMMARIZE( 'Table', 'Table'[Name], 'Table'[SKU ID] ),
        ALLEXCEPT( 'Table', 'Table'[Date], 'Table'[Country], 'Table'[Category] )
    )
VAR TableWithValues =
    ADDCOLUMNS ( BaseTable, "@value", [SUM] )
VAR Result =
    RANK ( DENSE, TableWithValues, ORDERBY ( [@value], DESC ) )
RETURN
    Result
andrew_tran
Frequent Visitor

However, I just realized that upon changing the formula from:

RANK_DESC = RANKX(ALLSELECTED('Table'[SKU ID]),[SUM],,DESC,Dense)

to:

RANK_DESC = RANKX(ALL('Table'[SKU ID],'Table'[Name]),[SUM],,DESC,Dense)

the formula then gave me the result I wanted

andrew_tran_0-1738764596289.png

Thanks a lot for providing the tip!

andrew_tran
Frequent Visitor

@divyed @bhanu_gautam Thank you so much for your quick response! I tried but it didn't work, the result was still the same unfortunately

divyed
Super User
Super User

Hello @andrew_tran ,

 

You are using ALLSELECTED which will respect external filters coming fro slicers hence the result. Try replacing ALLSELECTED with ALL and let us know.

 

RANK_DESC = RANKX(ALL('Table'[SKU ID]),[SUM],,DESC,Dense)

 

I hope this helps. 

 

Did I answer your query ? Mark this as solution if this helps, Kudos are appreciated.

 

Warm Regards,

Neeraj

 

 

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/
bhanu_gautam
Super User
Super User

@andrew_tran , Use ALL function

 

RANK_DESC = RANKX(ALL('Table'[SKU ID]), [SUM], , DESC, DENSE)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.