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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ksrini
Frequent Visitor

Ranking unique values by giving same rank to all duplicates

Hi,

 

I have to rank/index unique values in column which has year-week combination which goes like 2015-01, 2015-02..... 2015-52, 2016-01...to say 2020-30. Per each week, there are several entries, so i need to assign same rank irrespective of the number of duplicates. I tried RankEQ but i could not get it. Can you please suggest any ideas ? 

 

Thanks,

Srinivas

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

Hi @ksrini ,

 

You may try to use RANKX function. Since you have a year-week combination, there may be a column for the number of weeks and a column for the number of years. I will use these two columns for sorting. If not, it doesn't matter, you can follow the steps below.

 

1.I have a dataset which has the Date column and the Sales column. Create calculated columns as follows to get year-week combination.

 

WEEKNUMBER = WEEKNUM([Date],2)
YEAR = YEAR([Date])
YEARWKKE = [YEAR]&"-"&[WEEKNUMBER]

 

 

 

1.png

 

2.Now create other calculated columns to get ranking.

 

RANKYEAR = RANKX(ALL('Table'),[YEAR],,ASC,Dense)
RANKWEEK = RANKX(ALL('Table'),[WEEKNUMBER],,ASC,Dense)
RANKXYEAR&WEEK = RANKX ( ALL ( 'Table' ), [RANKWEEK] + [RANKYEAR] * 100,, ASC, DENSE )

 

 

 

2.png

 

You can check more details from here.

 

 

 

Best Regards,
Stephen Tao

 

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-stephen-msft
Community Support
Community Support

Hi @ksrini ,

 

You may try to use RANKX function. Since you have a year-week combination, there may be a column for the number of weeks and a column for the number of years. I will use these two columns for sorting. If not, it doesn't matter, you can follow the steps below.

 

1.I have a dataset which has the Date column and the Sales column. Create calculated columns as follows to get year-week combination.

 

WEEKNUMBER = WEEKNUM([Date],2)
YEAR = YEAR([Date])
YEARWKKE = [YEAR]&"-"&[WEEKNUMBER]

 

 

 

1.png

 

2.Now create other calculated columns to get ranking.

 

RANKYEAR = RANKX(ALL('Table'),[YEAR],,ASC,Dense)
RANKWEEK = RANKX(ALL('Table'),[WEEKNUMBER],,ASC,Dense)
RANKXYEAR&WEEK = RANKX ( ALL ( 'Table' ), [RANKWEEK] + [RANKYEAR] * 100,, ASC, DENSE )

 

 

 

2.png

 

You can check more details from here.

 

 

 

Best Regards,
Stephen Tao

 

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

 

Brilliant solution @v-stephen-msft. Really appreciate for the details and the example. It worked perfectly across all duplicates. I did try Rankx earlier itself but we need to standardize the two fields Year, Weeknum to get correct rank. Thanks for your help.

 

Regards,

Srinivas

pranit828
Community Champion
Community Champion

HI @ksrini 

Check teh below link.

https://community.powerbi.com/t5/Community-Blog/Power-BI-Handling-Duplicate-Rankings-Using-the-RANKX...

 





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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