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
Jessica_17
Helper III
Helper III

ranking on text column

I have one table, where I want to create rank on basis of text value,
The table is with one column which is sorted like this as shown below, and would like a rank on just this only, there is no corresponding aggregate function, neither any number column for this, Can anyone please help me achieve the desired output.

Input:-

batch
2
3
4
a3
a56
dfg

 

Output:- 

batchrank
21
32
43
a34
a565
dfg6


I have tried these measures, but it is not working,

Measure =
RANKX ( ALL ( 'Table1'[FullName] ), CALCULATE ( SUM ( 'Table1'[Index] ) ) )

It is showing error as data value is exceeded where original data has just 200 rows only.

1 ACCEPTED SOLUTION

21 REPLIES 21
Ahmedx
Super User
Super User

you can do this in power query.
it will be better this way

HI @Ahmedx 
I tried it in power query too, but it is not still not working.

to help you, tell us what didn’t work for and where

show on the screenshot or post the data where the rank is violated

HI @Ahmedx 
I am getting this error while using measures provided by other folks or even creating index column in power query.

Jessica_17_0-1704105431440.png

measure I am using is this

Row_Number =
RANKX(all('TableA cycle_step'[eq_no],'TableA cycle_step'[job_id], 'TableA cycle_step'[cntr_no], 'TableAcycle_step'[job_cmpl_time], 'TableAcycle_step'[job_fetching_time], 'TableAcycle_step'[from_loc]),'TableAcycle_step'[eq_no],MIN('TableAcycle_step'[eq_no]),ASC)

@Ritaf1983 , @Dangar332 
Here is the sample screenshot of original data , with the error by applying your method

Jessica_17_1-1704105627931.png


and also a measure is being used to filtere this data
ME =
VAR HourStep = SELECTEDVALUE('TableBhist cycle_step'[Hour_step])
VAR JobID = SELECTEDVALUE('TableAcycle_step'[job_id])
RETURN
IF(min('TableAcycle_step'[Hour_step]) = sELECTEDVALUE('TableBhist job_activity'[Hour_step]),1,0)

when this filter is applied the number also gets changed.

to know how to do this watch my video

https://1drv.ms/v/s!AiUZ0Ws7G26RjFqEfIAw03VVrDKN?e=f6rkrP

HI @Ahmedx 
Will this be feasible method even after the data source connectivity method gets changed to direct query in future?

yes it will work

HI @Ahmedx 
Thanks , it worked

hi, @Jessica_17 


refer below suggetion in LINK1  , LINK2  for same problem.

Dangar332
Super User
Super User

Hi, @Jessica_17 
try below

just adjust table and column name

 

 

 

Measure 4 = RANKX(all('Table (2)'[batch]),'Table (2)'[batch],MIN('Table (2)'[batch]),ASC)

 

 

 

 

Dangar332_1-1703842200480.png

Hi @Dangar332 
by using your solution I am getting count from 62, maybe because I have added other columns too. can this be changed irrespective of other column values too or by any other tables filter too.

 

 

hi, @Jessica_17 

it might happen 

but provide some data so see where problem occure

Ritaf1983
Super User
Super User

Hi @Jessica_17 
Try to use the measure :

rank_text = RANKX(ALLSELECTED('Table'[batch]),CALCULATE(max('Table'[batch])),,ASC)
Result :
Ritaf1983_0-1703841833642.png

pbix is attached

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

HI @Ritaf1983 
By using your solution, I am getting this error.

Jessica_17_0-1703851950705.png

 

Hi @Jessica_17 

Did you download a pbix and folllowed my steps?

If yes , please share link to the pbix of yours and i will try to help.

Hi @Dangar332 ,@Ritaf1983 , @Ahmedx 
The table visuals contains data like this, where Rank column should be shown as below.

JobsBatchcntrstarttimeendttimeFLRank 
4567672ABCSat, 09 Sep 2023 02:38:02Sat, 09 Sep 2023 02:40:02APC1
4567683NBXSat, 09 Sep 2023 02:39:03Sat, 09 Sep 2023 02:42:03APC2
4567693KJHSat, 09 Sep 2023 02:03:04Sat, 09 Sep 2023 02:05:04APC3
456755a3UTGSat, 09 Sep 2023 02:39:05Sat, 09 Sep 2023 02:43:05APC4
456725a56SHYSat, 09 Sep 2023 02:04:06Sat, 09 Sep 2023 02:08:06KPF5
456771dfgAKUSat, 09 Sep 2023 02:50:07Sat, 09 Sep 2023 02:57:07KPF6

hi, @Jessica_17 

try below for measure formula 

using measure = RANK(DENSE,ALL('Table'[Batch],'Table'[Jobs]),ORDERBY('Table'[Batch],ASC,'Table'[Jobs],ASC))

Dangar332_0-1704101156388.png

 

for column try below

using column = 
RANK(DENSE,ALL('Table'[Jobs],'Table'[Batch]),ORDERBY('Table'[Batch],asc,'Table'[Jobs],asc))

 

Dangar332_1-1704101222450.png

 

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

Hi @Jessica_17 ,

You can create a measure as below to get it, please find the details in the attachment.

Rank = RANKX ( ALL ( 'Table1' ), CALCULATE ( MAX ( 'Table1'[Batch] ) ),, ASC, DENSE )

vyiruanmsft_0-1704100221025.png

Best Regards

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

Hi, @Jessica_17 

try below for new column 

 

Column 2 = 
RANK(DENSE,ALL('Table'[Jobs],'Table'[Batch]),ORDERBY('Table'[Batch],asc,'Table'[Jobs],asc))

 

Dangar332_0-1704089822473.png

 

 

Hi @Jessica_17 
What is the ranking's purpose?
If the rank should be static, you can use @Ahmedx's suggestion.
If the table has duplicate batches.
You can duplicate the table, remove all unnecessary columns, and add an index column (with power query like in the attached images.
If the batches are unique you can just add an index.

Ritaf1983_0-1704086850344.png

 

Ritaf1983_1-1704086899762.png

Ritaf1983_3-1704087285507.png

 

Ritaf1983_2-1704087104078.png

create a relationship 

Ritaf1983_4-1704087463579.png

And use the index as a needed rank (note that you have duplicates)

Ritaf1983_5-1704087524980.png

 

if you need it as a dynamic measure :

Use a measure

rank_dynamic = RANKX(all('Table'),CALCULATE(max('Table'[batch])),,ASC)
Ritaf1983_6-1704088059719.png

New pbix is attached

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

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.