Community Trekker

Joined:

Jun 23, 2017

## Count(Rows Selected) & quickly summarize categories (under one or two columns) of rows selected. [1]

I have two columns selected once a graph launches (those categorical columns are on the X axis). As a user selects different points over the graph, specific rows are selected (like in normal graphing).

I'm looking for a way to do the following things:

1) Count number of rows selected

2) Identify what category (X coordinate) is selected on the graph (since only one will be selected at a time).

I'm amazed at how much difficulty I'm having with such a simple thing. I keep looking at the scripting index but to no avail.

1 ACCEPTED SOLUTION

Accepted Solutions

Super User

Joined:

Jun 22, 2012

Solution

## Re: Count(Rows Selected) & quickly summarize categories (under one or two columns) of rows selec

Here is a simple script that shows one way to handle the questions you ask

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" ); dt << bivariate( x( :height ), y( :weight ) ); dt << select rows( {2, 4, 6} ); Show( N Rows( dt << get selected rows ) ); Show( dt:height[(dt << get selected rows)[1]] ); Jim 5 REPLIES Super User Joined: Jun 22, 2012 Solution ## Re: Count(Rows Selected) & quickly summarize categories (under one or two columns) of rows selec Here is a simple script that shows one way to handle the questions you ask Names Default To Here( 1 ); dt = Open( "$SAMPLE_DATA\big class.jmp" );

dt << bivariate( x( :height ), y( :weight ) );

dt << select rows( {2, 4, 6} );

Show( N Rows( dt << get selected rows ) );
Show( dt:height[(dt << get selected rows)[1]] );
Jim

Community Trekker

Joined:

Jun 23, 2017

## Re: Count(Rows Selected) & quickly summarize categories (under one or two columns) of rows selec

Always coming to my aid! Thank you so much Jim. This is perfect and exactly what I needed. Reading a little more on this to see what else I can do :D

Staff

Joined:

Jun 23, 2011

## Re: Count(Rows Selected) & quickly summarize categories (under one or two columns) of rows selec

See Help > Scripting Index > Objects > Data Table > Make Row State Handler

Learn it once, use it forever!

Community Trekker

Joined:

Jun 23, 2017

## Re: Count(Rows Selected) & quickly summarize categories (under one or two columns) of rows selec

And thank YOU for this!

Reading about the Row state handler too as I'm pretty sure I can use this in another similar issue I was having :D You guys rock!

Community Trekker

Joined:

Jun 23, 2017

## Re: Count(Rows Selected) & quickly summarize categories (under one or two columns) of rows selec

I do have one last followup question though based on the solution you gave me.

In VBA for example there is a function 'countif' where I can specify for a range of cells (N Rows in my case) and count the occurrences of a given item in that column.

I can think of many ways to do this but most of them involve summaries. So say I use that second command you gave me Jim to figure out what element of X is selected. How can I then count the total occurrences of this in the table? (I know that's redundant but like I said there are two x variables and they are linked: months and weeks, so if I select a month, several weeks get selected, etc).

Could I use something like

r = Current Data Table() << get rows where( :height == 60 );

:name[r[Contains( :sex, :sex )]]; followed by the count you suggested?