cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
clarencelew
Level I

How do I add a filter column as a AND criteria

The syntax for Add Filter dictates that the new columns must be in the OR criteria.

Is there some way I can add rules in an iterative way?

dtf<<Add Filter(columns(column <,col>), <Where(clause)>)

Add one or more filter columns in a new OR group.

11 REPLIES 11
pmroz
Super User

Re: How do I add a filter column as a AND criteria

To figure this out:

Create a graph using Big Class

Add a local data filter with 2 variables (e.g. age and sex) using the AND button

Select criteria from both variables in the filter

Click the red triangle and select Script > Copy Script

Here's an example that shows the necessary syntax:

dt = open("$sample_data/Big Class.jmp");

// AND

Graph Builder(

     Show Control Panel( 0 ),

     Variables( X( :weight ), Y( :height ) ),

     Elements(

           Points( X, Y, Legend( 1 ), Jitter( 1 ) ),

           Smoother( X, Y, Legend( 3 ) )

     ),

     Local Data Filter(

           Location( {935, 334} ),

           Mode( Select( 0 ), Show( 1 ), Include( 1 ) ),

           Add Filter(

                columns( :age, :sex ),

                Where( :age == {12, 13, 14} ),

                Where( :sex == "M" )

           )

     )

);

clarencelew
Level I

Re: How do I add a filter column as a AND criteria

Hi PMroz,

Appreciate the response. But what I'm trying to achieve here is to add a filter to the current one after I've done some other crunching..



dt = open("$sample_data/Big Class.jmp");

  

gb = Graph Builder(

  Show Control Panel( 0 ),

  Variables( X( :weight ), Y( :height ) ),

  Points( X, Y, Legend( 1 ), Jitter( 1 ) ),

  Smoother( X, Y, Legend( 3 ) )

   ),

  Location( {935, 334} ),

  Mode( Select( 0 ), Show( 1 ), Include( 1 ) ),

  columns( :age, :sex ),

  Where( :age == {12, 13, 14} )

   //Where( :sex == "M" )

);

//do something else here...


gb << Add Filter(

  columns( :sex ),

  Where( :sex == "M" )

);



chungwei
Staff (Retired)

Re: How do I add a filter column as a AND criteria

Is this what you have in mind ?

dt = open("$sample_data/Big Class.jmp");

// AND

gb = Graph Builder(

     Show Control Panel( 0 ),

     Variables( X( :weight ), Y( :height ) ),

     Elements(

           Points( X, Y, Legend( 1 ), Jitter( 1 ) ),

           Smoother( X, Y, Legend( 3 ) )

     ),

);

df = gb << Local Data Filter(

           Mode( Select( 0 ), Show( 1 ), Include( 1 ) ),

           Add Filter(

                columns( :age ),

                Where( :age == {12, 13, 14} ),

           )

     )

df << Add Filter(

                columns( :sex ),

                Where( :sex == "M" ),

           )


jimloughlin
Level III

Re: How do I add a filter column as a AND criteria

are you missing a semi-colon (;) between the two df statements?

Jim Loughlin
Loughlin Consulting
clarencelew
Level I

Re: How do I add a filter column as a AND criteria

Hi Chung Wei,

That would only add the criteria as an OR condition not AND...

chungwei
Staff (Retired)

Re: How do I add a filter column as a AND criteria

sorry. I did not ask the question correctly.

I meant to ask if you would like to send separate messages to the data filter, instead of the way PMRoz showed.

newbie_alex
Level III

Re: How do I add a filter column as a AND criteria

I have the same issue. is there a way to add an AND filter instead of an OR filter (which was already shown by staff member chungwei)?
ian_jmp
Staff

Re: How do I add a filter column as a AND criteria

Using Chung-Wei's example:

dt = Open( "$sample_data/Big Class.jmp" );
// AND
gb = Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 1 ), Jitter( 1 ) ), Smoother( X, Y, Legend( 3 ) ) ),

);
Wait( 3 );
// OR
df = gb << Local Data Filter(
	Add Filter( columns( :age ) ),
	Add Filter( columns( :sex ) )
);
Wait( 3 );
// AND
df << removeLocalDataFilter;
df = gb << Local Data Filter(
	Add Filter( columns( :age, :sex ) )
);
newbie_alex
Level III

Re: How do I add a filter column as a AND criteria

Thank you for the quick reply. That will work.

 

Is there also a way to define the list of filter columns in a List variable and forward this to the filter (the name of my filter columns are dynamic)?

 

e.g.

filter_vars = {"age","sex"};

 

and somehow use filter_vars as an input for the data filter (instead of columns(:age,:sex))