Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Sum only selected rows of a column

Topic Options

- Start Article
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Aug 7, 2018 6:36 AM
(1927 views)

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

Solved Go to Solution

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Jim

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Sum only selected rows of a column

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Uday

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Sum only selected rows of a column