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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
SamuelO
Frequent Visitor

How to create a measure that ranks from the sort order of a text column (NOT numerical column).

Hello PowerBI Community,

 

I am new to PowerBI and trying out a few things here and would like your support.

 

I created a column rank that ranks my weekly dates as seen below;

PowerBICommunity.png

The challenge that Iam facing however is that I have measures that I am using to calculate the week over week counts difference and since I created WeekSortRank as column, it does not change dynamically depending on the filter, as seen below;

 

PowerBICommunity2.png

 

As you can see above, when filters are applied, the week old ranks are still maintained because it was a column and not a measure, and in the end, WeekSortEnrollmentLastWeek also ends up skipping some of the previous WeekSortEnrollement which is ideally supposed to pick from.

 

Therefore, I would like to have the WeekSortRank to be created by a measure since this adjusts well with filters and I believe this will inturn solve the WeekSortEnollmentLastWeek.

 

Cuurent  code that I used to create the above columns

WeekSortRank = RANKX(allselected('Data Table'), 'Data Table'[weekly_dates],,ASC,Dense)
 
WeekSortEnrollment = calculate(COUNTROWS(VALUES('Data Table'[Email])), FILTER('Data Table'[WeekSortRank]=MAX('Data Table'[WeekSortRank])))
 
WeekSortEnrollmentLastWeek = CALCULATE([WeekSortEnrollment], FILTER(ALLSELECTED('Data Table'),
'Data Table'[WeekSortRank] = MAX('Data Table'[WeekSortRank])-1))
 
Can I create this column (WeekSortRank = RANKX(allselected('Data Table'), 'Data Table'[weekly_dates],,ASC,Dense)) as a mesure?
 
Thank you all?
 
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @SamuelO ,

If you want to create a measure.

rankmeasure = RANKX(ALLSELECTED('Table'),CALCULATE( MAX('Table'[Date])),,ASC)

The final show:

vyalanwumsft_0-1657610473812.png

sort by text column is okey

Best Regards,
Community Support Team _ Yalan Wu
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

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @SamuelO ,

If you want to create a measure.

rankmeasure = RANKX(ALLSELECTED('Table'),CALCULATE( MAX('Table'[Date])),,ASC)

The final show:

vyalanwumsft_0-1657610473812.png

sort by text column is okey

Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @v-yalanwu-msft.

 

The code above worked fine for me by adding the ,dense.

 

I appreciate your time.

amitchandak
Super User
Super User

@SamuelO , If you are looking for this week Vs Last week and you have selected a week in the slicer , then you all not allselected

 

WeekSortEnrollmentLastWeek = CALCULATE([WeekSortEnrollment], FILTER(ALL('Data Table'),
'Data Table'[WeekSortRank] = MAX('Data Table'[WeekSortRank])-1))

 

 

refer

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thank you so much @amitchandak for your time on this.

 

So for the WeekSortRank above, how can I create a measure that ranks basing on the alphabetical sorting?

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Top Solution Authors