I have a large data set where the cycle changes over time. I would like to create a column that has an index by 1 at the start of each cycle and continues to count up until the next cycle starts then the counts starts back at 0. I have tried using the count and sequence functions shown below but I run into problems when my second cycle has more values that my first cycle (see diagram below where the cycle observation is the value I want the formula to produce and Column 109 is what is produced by the script.)
dt << New Column("Cycle Observation", Numeric, Formula (If(
:Cycle == 1, Sequence( 0, 1080, 1 ),
:Cycle == 2, Sequence( 0, 1439, 1 ),
:Cycle == 3, Sequence( 0, 360, 1 ),
:Cycle == 4, Sequence( 0, 360, 1 ),
:Cycle == 5, Sequence( 0, 360, 1 ),
:Cycle == 6, Sequence( 0, 180, 1 ),
:Cycle == 7, Sequence( 0, 180, 1 ),
:Cycle == 8, Sequence( 0, 180, 1 ),
:Cycle == 9, Sequence( 0, 180, 1 ),
:Cycle == 10, Sequence( 0, 180, 1 ),
Sequence( 0, 180, 1 )
)));