cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Issue with the selection of the Data table

Hello,

 

I hope you are doing well.

This is a very long and unoptimized code to perform 2 subsets from two different data sets ("CL and Spec" and "Data set"). There is a text box to choose what rows to select according to the levels of the data sets.

However, the issue is after the subset of the first data table is performed (data set named "CL and Spec"), the subset of the second data set (named "Data set") doesn't work without any error message. There is just no subset that is performed. My understanding is that there is an issue with my way of selecting the data set to select for the subset. Or I didn't use the "Current Data Table" function correctly.

 

Here is my code:

 

dt2 = Data Table( "CL and Spec" );
Current Data Table( dt2 );

// get unique values from the strength column
Summarize( dt2, levels = by( :Product ) );

// construct a window containing checkboxes
New Window( "Selection",
	modal,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
		V List Box(
			Text Box( "Select values:" ),
			here:cb = Check Box( levels ),
			Spacer Box( size( 0, 20 ) ),
			Button Box( "Create Subset", doSubset() )
		)
	)
);

// define function to perform when button is cliccked
doSubset = Function( {},
	{default local}, 

	dt2 = Current Data Table();
	dt2 << clear select;

		// get user selections
	selected = here:cb << get selected;
		
		// iterate over each of the selected values
	// and select the associated rows
	For( i = 1, i <= N Items( selected ), i++,
		rows = dt2 << select  where( :Product == selected[i], current selection( "extend" ) )
	);
		// create a subset table
	dt2 << subset( selected rows( 1 ), selected columns only( 0 ) );
	dt2 << clear select;

);

// Define the control and specification limits
LSL = dt2:LSL[1];
USL = dt2:USL[1];

dt = Data Table( "Data Set" );
Current Data Table( dt );

// get unique values from the strength column
Summarize( dt, levels = by( :Strength ) );

// construct a window containing checkboxes
New Window( "Selection",
	modal,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
		V List Box(
			Text Box( "Select values:" ),
			here:cb = Check Box( levels ),
			Spacer Box( size( 0, 20 ) ),
			Button Box( "Create Subset", doSubset() )
		)
	)
);


// define function to perform when button is cliccked

doSubset = Function( {},
	{default local}, 

	dt = Data Table( "Data Set" );
	Current Data Table( dt );
	dt << clear select;

		// get user selections
	selected = here:cb << get selected;
		
		// iterate over each of the selected values
	// and select the associated rows
	For( i = 1, i <= N Items( selected ), i++,
		rows = dt << select  where( :Strength == selected[i], current selection( "extend" ) )
	);
		// create a subset table
	dt << subset( selected rows( 1 ), selected columns only( 0 ) );
		
	dt << clear select;

);

I hope my question and problem is clearly expressed  

 

Thank you very much for you help and have a nice day !

 

Jean

2 REPLIES 2
ErraticAttack
Level VI

Re: Issue with the selection of the Data table

I don't have your tables, but this is how I would approach a similar issue:

Names Default to Here( 1 );
dt2 = Data Table( "CL and Spec" );

// get unique values from the strength column
levels = Associative Array( dt2:product ) << Get Keys;

// construct a window containing checkboxes
continue = 0;
New Window( "Selection",
	<<Modal
,
	<<On Validate(
		continue = 1;
		selected = cb << Get Selected;
		1
	)
,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
		V List Box(
			Text Box( "Select values:" ),
			cb = Check Box( levels ),
			Spacer Box( size( 0, 20 ) )
		)
	)
);
If( !continue, Stop() ); //user aborted
If( N Items( selected ) == 0, Stop() );

//do the subset
rows = dt2 << Get Rows Where( Contains( As Constant( selected ), :Product ) );
dt = dt2 << Subset( Rows( rows ), All Columns, Not Linked );

// Define the control and specification limits
LSL = dt2:LSL[1];
USL = dt2:USL[1];


// get unique values from the strength column
levels = Associative Array( dt:STRENGTH ) << Get Keys;

// construct a window containing checkboxes
continue = 0;
New Window( "Selection",
	<<Modal
,
	<<On Validate(
		continue = 1;
		selected = cb << Get Selected;
		1
	)
,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
		V List Box(
			Text Box( "Select values:" ),
			cb = Check Box( levels ),
			Spacer Box( size( 0, 20 ) )
		)
	)
);
If( !continue, Stop() ); //user aborted
If( N Items( selected ) == 0, Stop() );

// define function to perform when button is cliccked
rows = dt << Get Rows Where( Contains( As Constant( selected ), :STRENGTH ) );
dt << Subset( Rows( Rows ), All Columns, Not Linked );

 

Jordan

Re: Issue with the selection of the Data table

In fact my concern is that I want to open 2 different data sets and use data from the first one, and then to switch to the next one.

I used the "Current Data Table" function before performing the subset.

 

A first part of the code is to load the "CL and Spec" data set, open a text box, to subset a row of the "CL and Spec" data set and store the parameters "LSL" and "USL" in the LSL and USL variables. Then the "CL and Spec" data set is not used any more.

 

Names Default to Here( 1 );
dt2 = Data Table( "CL and Spec" );

// get unique values from the strength column
levels = Associative Array( dt2:product ) << Get Keys;

// construct a window containing checkboxes
continue = 0;
New Window( "Selection",
	<<Modal
,
	<<On Validate(
		continue = 1;
		selected = cb << Get Selected;
		1
	)
,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
		V List Box(
			Text Box( "Select values:" ),
			cb = Check Box( levels ),
			Spacer Box( size( 0, 20 ) )
		)
	)
);
If( !continue, Stop() ); //user aborted
If( N Items( selected ) == 0, Stop() );

//do the subset
rows = dt2 << Get Rows Where( Contains( As Constant( selected ), :Product ) );
dt = dt2 << Subset( Rows( rows ), All Columns, Not Linked );

// Define the control and specification limits
LSL = dt2:LSL[1];
USL = dt2:USL[1];

Then the second part of the code is to load the "Data set" data set, open a text box, and to subset rows of the "Data set" data set. 

dt = Data Table( "Data Set" );
Current Data Table( dt );

// get unique values from the strength column
Summarize( dt, levels = by( :Strength ) );

// construct a window containing checkboxes
New Window( "Selection",
	modal,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
		V List Box(
			Text Box( "Select values:" ),
			here:cb = Check Box( levels ),
			Spacer Box( size( 0, 20 ) ),
			Button Box( "Create Subset", doSubset() )
		)
	)
);


// define function to perform when button is cliccked

doSubset = Function( {},
	{default local}, 

	dt = Data Table( "Data Set" );
	Current Data Table( dt );
	dt << clear select;

		// get user selections
	selected = here:cb << get selected;
		
		// iterate over each of the selected values
	// and select the associated rows
	For( i = 1, i <= N Items( selected ), i++,
		rows = dt << select  where( :Strength == selected[i], current selection( "extend" ) )
	);
		// create a subset table
	dt << subset( selected rows( 1 ), selected columns only( 0 ) );
		
	dt << clear select;

);

However, the second data is not loaded or there no subsets of the rows...

 

Thank you very much for your help!