Check if multiple column values fall within rangeSample table:
Part Test 1 Test 2 Test 3 Test 4 A 0.2 0.4 0.3 0.1 B 0.2 0.3 0.4 0.6 C 0.7 0.1 0.2 0.4I would like to add a column to this table that evaluates every value in columns Test 1-Test 4, and if all fall within a range to output "Yes".
For example, if my range was 0 < values < 0.5, the output would look like this (I've highlighted failing values in red)
Part Test 1 Test 2 Test 3 Test 4 Yes/No A 0.2 0.4 0.3 0.1 Yes B 0.2 0.3 0.4 0.6 No C 0.7 0.1 0.2 0.4 NoIs there a simple way to achieve this with JSL?
Re: Check if multiple column values fall within range<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />hi hooshies,
to answer your exact question the following script can do it.
A more general solution depends on the aspect that needs generalizing (i.e. more columns, different ranges for different columns and whether you want it in a column formula or just to be calculated once by jsl)
dt = New Table( "Data source",
Add Rows( 3 ),
New Column( "Part", Character, Nominal, Set Values( {"A", "B", "C"} ) ),
New Column( "Test 1", Set Values( [0.2, 0.2, 0.7] ) ),
New Column( "Test 2", Set Values( [0.4, 0.3, 0.1] ) ),
New Column( "Test 3", Set Values( [0.3, 0.4, 0.2] ) ),
New Column( "Test 4", Set Values( [0.1, 0.6, 0.4] ) ),
);
dt << New Column( "Yes/No",
Character,
Nominal,
Formula(
If(
Maximum(
Abs( :Test 1 ),
Abs( :Test 2 ),
Abs( :Test 3 ),
Abs( :Test 4 )
) > 0.5,
"No",
"Yes"
)
)
);
Re: Check if multiple column values fall within range<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Ron,
Thanks for you response. The script you provided gets the job done in this situation, but I would like a more robust/general solution (for example, when the limits of my testing criteria are 0.23 < test values < 0.5).
Is there a way to set a column formula or script a solution where multiple columns are treated as an array? In pseudocode:
lower_limit = 0.23
upper_limit = 0.5
If lower_limit < [Column(2), Column(3), Column(4), Column(5)] < upper_limit
disp "Yes"
Else
disp "No"
The pseudocode here would test each value in columns 2-5 individually against the limits, and output "Yes" if all are in range.
Multiple AND/OR statements would achieve this, but seems like an elementary approach.
Thanks!
Re: Check if multiple column values fall within range<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />ron_horne's method can be generalized. The key is to recognize that the Minimum() and Maximum() functions return the min/max value of their arguments. So, as you pose it, the comparison it can be written:
Minimum( :Test 1, :Test 2, :Test 3, :Test 4 ) > 0.23 &
Maximum( :Test 1, :Test 2, :Test 3, :Test 4 ) < .5;
-Jeff
Re: Check if multiple column values fall within range<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />New Column("In Range?", Formula(
If(
Min( :Test 1, :Test 2, :Test 3, :Test 4 ) > 0 &
Max( :Test 1, :Test 2, :Test 3, :Test 4 ) < 0.5,
"Yes",
"No"
)
)