cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
OneNorthJMP
Level V

Rank Unique

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)

 

LabelRankWhat I want
NVM_VMAX_PRG_EVENR2_DCMP[1],80376,max11
NVM_VMAX_PRG_EVENR2_DCMP[1],80376,max21
NVM_VMAX_PRG_EVENR2_DCMP[1],80376,max31
NVM_VMAX_PRG_EVENR2_DCMP[1],81999,max42
NVM_VMAX_PRG_EVENR2_DCMP[1],81999,max52
NVM_VMAX_PRG_EVENR2_DCMP[1],81999,max62
NVM_VMAX_PRG_EVENR2_DCMP[1],86491,max73
NVM_VMAX_PRG_EVENR2_DCMP[1],86491,max83
NVM_VMAX_PRG_EVENR2_DCMP[1],86491,max93
2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Rank Unique

There are a couple of ways to do this....(that I can think of, this early in the morning)

  1. Use a summary table to create the ranks
    1. Run Tables==>Summary 
    2. Group by your Label column
    3. Assuming the output data table is sorted from low to high, create a new column called "Rank" and give it the formula........Row()
    4. Run    Tables==>Update to join the summary table back to the original table, matching on the Label column
  2. Create a new Rank formula column
    1. Sort the data by Label
    2. Create a new column called Rank with the formula
      If( Row() == 1,
      	count = 1,
      	If( :Label != Lag( :Label ),
      		count
      		++)
      );
      count;
    3. 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.
Jim

View solution in original post

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Rank Unique

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 ) );

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: Rank Unique

There are a couple of ways to do this....(that I can think of, this early in the morning)

  1. Use a summary table to create the ranks
    1. Run Tables==>Summary 
    2. Group by your Label column
    3. Assuming the output data table is sorted from low to high, create a new column called "Rank" and give it the formula........Row()
    4. Run    Tables==>Update to join the summary table back to the original table, matching on the Label column
  2. Create a new Rank formula column
    1. Sort the data by Label
    2. Create a new column called Rank with the formula
      If( Row() == 1,
      	count = 1,
      	If( :Label != Lag( :Label ),
      		count
      		++)
      );
      count;
    3. 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.
Jim
OneNorthJMP
Level V

Re: Rank Unique

Hi Jim,

Thanks for advice. For the #2 solution. How do remove the formula by using JSL instead of doing it manually?
txnelson
Super User

Re: Rank Unique

dt = current data table();
dt:Rank << delete formula;
Jim
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Rank Unique

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 ) );
OneNorthJMP
Level V

Re: Rank Unique

Thanks Jim & MS. It work brilliantly!