cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
lala
Level IX

Can this formula be completed in one step?

I tried, but failed

Thanks Experts!

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
ca = "A";New Column( ca );
Column( ca ) << Formula( height / Lag( height, 5 ) > 1.1 );
dt << run formulas;
Column( ca ) << deleteFormula;
ca = "SumA";New Column( ca );
Column( ca ) << Formula( Sum( A[Index( Row() - 9, Row() )] ) );
dt << run formulas;
Column( ca ) << deleteFormula;
ca = "Sum1";New Column( ca );
Column( ca ) << Formula( Sum( height[Index( Row() - 9, Row() )] / height[Index( Row() - 9 - 5, Row() - 5 )] > 1.1 ) );
dt << run formulas;
Column( ca ) << deleteFormula;//??

2024-07-10_9-54-42.png

1 ACCEPTED SOLUTION

Accepted Solutions
lala
Level IX

Re: Can this formula be completed in one step?

4 REPLIES 4
jthi
Super User

Re: Can this formula be completed in one step?

What is the formula supposed to do and is there a specific reason to try and force it to be a single step? 

 

-Jarmo
txnelson
Super User

Re: Can this formula be completed in one step?

Here is one way to do it

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
ca = "A";
New Column( ca, set each value( :height / Lag( :height, 5 ) > 1.1 ) );
ca = "SumA";
New Column( ca, set each value( Sum( :A[Index( Row() - 9, Row() )] ) ) );
ca = "Sum1";
New Column( ca,
	set each value(
		As Constant(
			a = [];
			For( i = 1, i <= N Rows( Current Data Table() ), i++,
				If( i > 5,
					a = a || ((:height[i] / :height[i - 5]) > 1.1),
					a = a || .
				)
			);
		);
		If( Row() > 5,
			Sum( A[Index( Max(6,Row() - 9), Row() )], . )
		);
	)
);

 Here is another way

ca = "Sum1a";
New Column( ca,
	set each value(
		If( Row() <= 5,
			val = .,
			theRows = Index( Max( 6, Row() - 9 ), Row() );
			val = .;
			For Each( {calc}, theRows,
				val = Sum( val, (:height[calc] / :height[calc - 5]) > 1.1 )
			);
		);
		val;
	)
);
Jim
lala
Level IX

Re: Can this formula be completed in one step?

Thank Jim!

OK、

It's a formula I forgot and got in the community before.

Now think of it, it is OK:

:\

ca = "Sum1";New Column( ca );
Column( ca ) << Formula( Sum( height[Index( Row() - 9, Row() )] :\ height[Index( Row() - 9 - 5, Row() - 5 )] > 1.1 ) );
dt << run formulas;
Column( ca ) << deleteFormula;

 

lala
Level IX

Re: Can this formula be completed in one step?

2024-07-10_12-50-57.png

Recommended Articles