cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

Sum only selected rows of a column

twillkickers
Level III

Is there an easy way to sum only the selected rows of a column and save the value to a global variable?

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User


Re: Sum only selected rows of a column

::myGlobalVariable = Col Sum( If( Selected(), :height, . ) );
Jim

View solution in original post

6 REPLIES 6
txnelson
Super User


Re: Sum only selected rows of a column

Here is a simple script to do what you want

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
dt << set table variable( "my variable", Col Sum( If( Selected(), :height, . ) ) );
Jim
twillkickers
Level III


Re: Sum only selected rows of a column

How is this type of variable called? I can't call it using ::my variable

uday_guntupalli
Level VIII


Re: Sum only selected rows of a column

@twillkickers
        They are referenced the same way you would reference a column 

 

dt = Open( "$SAMPLE_DATA/big class.jmp" );
dt << Select Randomly(0.1); 
dt << set table variable( "myvariable", Col Sum( If( Selected(), :height, . ) ) );

Print(:myvariable);
Best
Uday
txnelson
Super User


Re: Sum only selected rows of a column

::myGlobalVariable = Col Sum( If( Selected(), :height, . ) );
Jim
twillkickers
Level III


Re: Sum only selected rows of a column

Thank you. This works for me. Is there a function similar to "set table variable" which sets the value as a global variable? (:: instead of :) I am having to take the table variable and save it as a global variable to do my calculations.
dale_lehman
Level VII


Re: Sum only selected rows of a column

If you want to do this without using a script, first select the rows (using whatever method you want).  Then, under Rows-Select-Name selection in column, you create a column of 0 and 1 that identifies the selected rows.  Then create a new column using the Column Sum formula and put the newly created Named selection in column as the By variable.  The result will show the sum for the selected and unselected rows.