Thanks Jim & MS. It work brilliantly!
If you want a column formula this should work. Independent of sorting.
Local( {L = Associative Array( :Label ) << get keys}, Loc( L, :Label ) )
Same approach could be used in JSL without a column formula.
dt = Current Data Table();
dt << New Column( "Rank Unique", continuous );
L = Associative Array( :Label ) << get keys;
For Each Row( :Rank Unique = Loc( L, :Label ) );
dt = current data table();
dt:Rank << delete formula;
There are a couple of ways to do this....(that I can think of, this early in the morning)
- Use a summary table to create the ranks
- Run Tables==>Summary
- Group by your Label column
- Assuming the output data table is sorted from low to high, create a new column called "Rank" and give it the formula........Row()
- Run Tables==>Update to join the summary table back to the original table, matching on the Label column
- Create a new Rank formula column
- Sort the data by Label
- Create a new column called Rank with the formula
If( Row() == 1,
count = 1,
If( :Label != Lag( :Label ),
count
++)
);
count;
- Be sure to go to Column Info and remove the after the column is created. The reason for this is that since the formula is based upon the order of the data, and the completeness of the data, any changes in the data(sorting etc.) will rerun the formula and possibly change the rankings.
I want to calculate a new column to rank a column uniquely. Below are the example output that i want to achieve. But by using the JSL rank formula doesn't help me to achieve what i want. Can anyone please advise me?
The formula i use is Col Rank(:Label)
| Label | Rank | What I want |
| NVM_VMAX_PRG_EVENR2_DCMP[1],80376,max | 1 | 1 |
| NVM_VMAX_PRG_EVENR2_DCMP[1],80376,max | 2 | 1 |
| NVM_VMAX_PRG_EVENR2_DCMP[1],80376,max | 3 | 1 |
| NVM_VMAX_PRG_EVENR2_DCMP[1],81999,max | 4 | 2 |
| NVM_VMAX_PRG_EVENR2_DCMP[1],81999,max | 5 | 2 |
| NVM_VMAX_PRG_EVENR2_DCMP[1],81999,max | 6 | 2 |
| NVM_VMAX_PRG_EVENR2_DCMP[1],86491,max | 7 | 3 |
| NVM_VMAX_PRG_EVENR2_DCMP[1],86491,max | 8 | 3 |
| NVM_VMAX_PRG_EVENR2_DCMP[1],86491,max | 9 | 3 |
This is long-since solved, but I found a solution to this yesterday that I figured I'd share in case it's helpful to anyone. Create a new formula column with this formula:
Col Maximum(
Col Rank(
If( Row() == Col Minimum( Row(), :Label ),
:Label,
.
)
),
:Label
)
Basically this first creates a new array with the label in the row corresponding to its first instance in the original column, and "." everywhere else. Then we ask for the ranking of each label, which results in another array with the label ranking instead of the label itself, and then finally we output an array with the ranking in all rows with that label, and that's what ends up in the formula column.
In my case I was trying to rank groups of sets of data based on their highest value in another column -- e.g. with columns Group, Set, Time, Value, I wanted to find the set's rank within the group based on the highest Value observed across time. Here's a formula that worked:
Col Maximum(
Col Rank(
If ( Row() == Col Minimum( Row(), :Group, :Set),
Col Maximum( :Value, :Group, :Set ),
.
),
:Group,<BR /> <<TIE></TIE> ),
:Group, :Set
)
I don't know if this is the best way, but it works, and ChatGPT couldn't offer a solution at all, so maybe this will help someone.