Subscribe Bookmark RSS Feed

Running Count of Repeated Values JSL Script?

aandw

Community Trekker

Joined:

Mar 12, 2015

I would like to script a running count or cumulative sum of repeated values within a column.

For example, first appearance should equal 1, max value of count by value specified should equal the cumulative sum of the value within the column.

colorcount_color
RED1
RED2
BLUE1
YELLOW1
RED3

Ideally, the output for :count_color would not need the data table to be sorted by :color

Thanks.

3 REPLIES
ms

Super User

Joined:

Jun 23, 2011

Try this expression in a column formula (or in a For Each Row() loop);

Eval(Eval Expr(Col Sum(Row() <= Expr(Row()), :color)));

aandw

Community Trekker

Joined:

Mar 12, 2015

Using the Eval command under formula generates an output, but all values = 0

Perhaps I have misinterpreted. My column formula is below.

// Running Count

New Column("count_color",

  numeric,

  continuous,

  formula(

  Eval(Eval Expr(Col Sum(Row() <= Expr(Row()), :color)))

  )

);

Craige_Hales

Staff

Joined:

Mar 21, 2013

Either paste the formula from MS into the formula editor or wrap the formula in NameExpr (longer explanation here):


New Column( "count",


  Numeric,


  "Continuous",


  Format( "Best", 12 ),


  Formula( Name Expr( Eval( Eval Expr( Col Sum( Row() <= Expr( Row() ), :color ) ) ) ) )


),



There is a bug in JMP that you've helped uncover; the resulting table does not include the Name Expr( ) wrapper around the formula when the table's <<getscript command is used.  Thanks!

Craige