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

Need a column based on selective condition on other columns

Hi All,

I am looking for % of fails in measurement procedure. My requirement and sample data is below.

 

HSS_0-1646382549163.png

 

Any help here?
Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
Georg
Level VII

Re: Need a column based on selective condition on other columns

I'm not really sure what you are going to do.

If you want to add that calculation to the current data table, the below code will work. You need to put that calculation into "Formula()".

If you have a column and would like to script it, the best way is always to copy the table script from red triangle menu of table. There you can get and review the script, how to generate the table (or column) by script.

 

Names Default To Here( 1 );

dt = Current Data Table();

dt << New Column( "Pattern",
	Expression,
	"None",
	Formula(
		(row_index_lst = {} ; row_Time_A = :Time_A ; row_Sample = :Sample ; threshold = 60 * 15 ;
		For Each Row(
			If( Abs( :Time_A - row_Time_A ) < threshold & :Sample == row_Sample,
				Insert Into( row_index_lst, Row() )
			)
		));
		(:Measurement << get values)[row_index_lst];
	),
	Set Display Width( 232 )
);

 

Georg

View solution in original post

4 REPLIES 4
Georg
Level VII

Re: Need a column based on selective condition on other columns

The most tricky part here is to define a proper grouping column (see Avg_Time and concatenated with Sample --> Group).

This is similar to your "count" concatenated with Sample.

If I would need to calculate the requirements, I would do it like shown in the table in Column "Result". Behind the scenes it tries to find in each row: all rows belonging to the same group, and shows the measurement Points in column "Measurement in Group".

Please see attached table for the details.

 

Georg_0-1646426953083.png

 

Georg
HSS
HSS
Level IV

Re: Need a column based on selective condition on other columns

Hi Georg,
It seems working fine in table column Formula. But I am not able to make it into a script. In also tried similar approach based on For loop and different column but I am not able to generate pattern of measurements to get the final results. Here is the script I am trying --

 

 

/////////////////////////////////////////////////////////////////
dt = Current Data Table();
dt << New Column( "Pattern0",
Expression,
(row_index_lst = {} ; row_Time_A = :Time_A ; row_Sample = :Sample ; threshold = 60 * 15 ;
For Each Row(
If( Abs( :Time_A - row_Time_A ) < threshold & :Sample == row_Sample,
Insert Into( row_index_lst, Row() )
)
));
(:Measurement << get values)[row_index_lst];
);

///////////////////////////////////////////


// similar approach but based on different column and For loop--


//////////////////////////////////////////////////////
dt << New Column( "Pattren",
Expression,
For( i = 1, i <= N Rows( dt ), i++,
Row_List = {};
If(
:Count == Lag( :Count, -1 ) & :Sample == Lag( :Sample, -1 ) | :Count == Lag( :Count, 1 ) &
:Sample == Lag( :Sample, 1 ),
Insert Into( Row_List, Row() )
);
(:Measurement << get values)[Row_List];
)
);
/////////////////////////////////////////////////////////////

 

Both are giving just empty columns. Any suggestion how can I convert your formula to a script ?
Thanks again.

Georg
Level VII

Re: Need a column based on selective condition on other columns

I'm not really sure what you are going to do.

If you want to add that calculation to the current data table, the below code will work. You need to put that calculation into "Formula()".

If you have a column and would like to script it, the best way is always to copy the table script from red triangle menu of table. There you can get and review the script, how to generate the table (or column) by script.

 

Names Default To Here( 1 );

dt = Current Data Table();

dt << New Column( "Pattern",
	Expression,
	"None",
	Formula(
		(row_index_lst = {} ; row_Time_A = :Time_A ; row_Sample = :Sample ; threshold = 60 * 15 ;
		For Each Row(
			If( Abs( :Time_A - row_Time_A ) < threshold & :Sample == row_Sample,
				Insert Into( row_index_lst, Row() )
			)
		));
		(:Measurement << get values)[row_index_lst];
	),
	Set Display Width( 232 )
);

 

Georg
HSS
HSS
Level IV

Re: Need a column based on selective condition on other columns

Thanks George,
It is working fine. I forget to put everything in  "Formula ( )". thanks again.