# How to calculate the Rank?

Hi All,

I hope everyone doing well.
I stuck in a scenario that I want to calculate the Rank of the students from the list of marks list which is in excel.
Like
Total_Marks | Rank
459 2
296
260
435
342
262
494 1
380
340
323

From above marks I need to calculate the rank of the each student.
Which student scored more marks he should assign with 1st rank,then 2nd rank and so on.

From above example the guy who scored 494 will need to assign 1st rank and for a guy who scored 459 should get the rank 2nd and so on the guy who scored least marks should get last rankâ€¦

Please somene help me to resolve the issue.

1 Like

`dt = dt.Select("",Total_Marks desc").CopyToDataTable()`

then update the Rank in increment mode.

Regards,
Arivu

1 Like

I think you can use Sort datatable.
Specify the column you want to sort in, and then use the descending sort. If there is no column to index, why donâ€™t you add one?

1 Like

Can you please elaborate with the code??

lets assume you do have a Excel with2 cols : the filled TotalMarks, Rank

clone dtData for the report (Assign Activity)
dtReport | DataTable = dtData.Clone

Fillup dtReport (Assign Acitvity)
dtReport =

``````dtData.AsEnumerable.OrderByDescending(Function (x) Cint(x(0).toString)).Select(Function (x,i) dtReport.Rows.Add(new Object(){x(0),i})).CopyToDataTable
``````

As Alternate we can also do it with essentials

• sort the datatable
• for each row
• using for each row output index for the rank updating
1 Like

Hi @HeartCatcher
Sort Rank.zip (7.3 KB)
please find the sample code for the above query , i have done in a simple way (Non Linq)
just run the file and try to understand how it works ,attached input file too

Thanks

1 Like

let me know if it works or not

thanks

@HeartCatcher Just go to excel and check any spaces in column name
Test.xlsx (7.8 KB)
or just use this

or u can only create an excel with columnname â€śMarksâ€ť and â€śRankâ€ť

and leave rank column empty

@HeartCatcher you can try with applying Excel formula in UIpath in assign activityâ€¦
in write cell you have to do this steps â†’

and in assign â†’

Let me Know if it Works or not.

1 Like

What is K and L here??

1 Like

Done some changes in @nikhil.girish flow

Can you please check on this

Sort Rank.zip (7.3 KB)

Regards
Sudharsan