cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • See how to interactively organize and restructure data for analysis. Register for May 29 webinar, 2pm US ET.

Discussions

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

How do I get a JSL script to Sum cells based of other cells.

Hi All,

I've gotten stuck trying to write a script that will Sum cells based on 2 other cells within the same row.

Im able to select the correct rows with 

dt << row selection (Select where (:Column 3== CurrentWrkWk & :Column 1== "TIM703"));

Final answer I expect is

The sum should be 3.913.

Ive been reading the scripting index but am lost

 

 

Names Default To Here( 1 );
Clear Globals();
dt = current data table();
CurrentWrkWk = 202450;


a1 == dt << row selection (Select where (:Column 3== CurrentWrkWk & :Column 1== "TIM703"));
Var1 =Col Cumulative Sum(:StateHour, a1);

show(Var1);

 

>

JMP version 17

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How do I get a JSL script to Sum cells based of other cells.

For sum you can also use data table subscripting

 

Names Default To Here( 1 );

dt = Open("$SAMPLE_DATA/Big Class.jmp");

age_of_interest = 12;
sex_of_interest = "F";

rows_of_interest = dt << Get Rows Where(:age == age_of_interest & :sex == sex_of_interest);

res = Sum(dt[rows_of_interest, "height"]);

 

 

-Jarmo

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How do I get a JSL script to Sum cells based of other cells.

I think this might do what you want

Var1 = Col Cumulative Sum(
	If( :Column 3 == CurrentWrkWk & :Column 1 == "TIM703",
		:StateHour,
		.
	),
	a1
);
Jim
jthi
Super User

Re: How do I get a JSL script to Sum cells based of other cells.

For sum you can also use data table subscripting

 

Names Default To Here( 1 );

dt = Open("$SAMPLE_DATA/Big Class.jmp");

age_of_interest = 12;
sex_of_interest = "F";

rows_of_interest = dt << Get Rows Where(:age == age_of_interest & :sex == sex_of_interest);

res = Sum(dt[rows_of_interest, "height"]);

 

 

-Jarmo

Re: How do I get a JSL script to Sum cells based of other cells.

Hi Jthi,

Thank you this has worked

Recommended Articles