Setting Values in a Column with ChooseI'm having what I'm sure is a simple issue with setting values in a column using the Choose function. Below is a test script along with a table showing desired output.
Names Default To Here( 1 );
startTime = 3742070400;
endTime = 3742074000;
dt = New Table( "Test",
Add Rows( 60 ),
New Column( "Timestamp", Format( "m/d/y h:m", 19 ), Set Display Width( 175 ) )
);
For Each Row( :Timestamp[] = Sequence( startTime, endTime, 60 ) );
aggOption = 1; // This will eventually be a pulldown menu with choices
New Column( "Agg Minute",
Numeric,
"Ordinal",
Format( "Best", 12 ),
Set Display Width( 116 )
);
// Script below is the problem. I tried For Each Row and Set Values and a combination
// of both but the column always is blank. See Interpolated Data table for what it
// should look like.
dt:"Agg Minute"n << For Each Row(
Choose( aggOption,
If(
Minute( :Timestamp ) < 15, 15,
Minute( :Timestamp ) < 30, 30,
Minute( :Timestamp ) < 45, 45,
0
),
If(
Minute( :Timestamp ) < 14, 0,
Minute( :Timestamp ) < 29, 15,
Minute( :Timestamp ) < 44, 30,
45
),
If(
0 < Minute( :Timestamp ) <= 15, 15,
15 < Minute( :Timestamp ) <= 30, 30,
30 < Minute( :Timestamp ) <= 45, 45,
0
)
)
);
Notice when you run the script the Agg Minute column is blank. I've tried Set Values and For Each Row and a combination of both but I can't seem to get it to work.
As always, any assistance is greatly appreciated.
Thanks.
Automation and ScriptingmacOSRe: Setting Values in a Column with ChooseI can get it to work as a column formula if I set a local variable. But then I can't use my combo box result.
Here is that code. There is obviously much more I need to learn about JSL. It is very easy to auto-generate code. But often when I try to customize it, it breaks and I don't know enough yet to fix it.
Arrgh.
New Column( "Agg Minute",
Numeric,
"Ordinal",
Format( "Best", 12 ),
Set Display Width( 116 ),
Formula(
Local( {aggOption = 1},
Choose( aggOption,
If(
Minute( :Timestamp ) < 15, 15,
Minute( :Timestamp ) < 30, 30,
Minute( :Timestamp ) < 45, 45,
0
),
If(
Minute( :Timestamp ) < 15, 0,
Minute( :Timestamp ) < 30, 15,
Minute( :Timestamp ) < 45, 30,
45
),
If(
0 < Minute( :Timestamp ) <= 15, 15,
15 < Minute( :Timestamp ) <= 30, 30,
30 < Minute( :Timestamp ) <= 45, 45,
0
)
)
)
)
);Re: Setting Values in a Column with ChooseYou are using For Each Row incorrectly. You don't send it to a column, it is a function you provide with (optional) data table and body argument and within body you can set values to columns.
Here is fixed version
Names Default To Here(1);
startTime = 3742070400;
endTime = 3742074000;
dt = New Table("Test",
Add Rows(60),
New Column("Timestamp", Format("m/d/y h:m", 19), Set Display Width(175))
);
For Each Row(:Timestamp[] = Sequence(startTime, endTime, 60));
aggOption = 1;
New Column("Agg Minute", Numeric, "Ordinal", Format("Best", 12), Set Display Width(116));
For Each Row(dt,
:"Agg Minute"n = Choose(aggOption,
If(
Minute(:Timestamp) < 15, 15,
Minute(:Timestamp) < 30, 30,
Minute(:Timestamp) < 45, 45,
0
),
If(
Minute(:Timestamp) < 14, 0,
Minute(:Timestamp) < 29, 15,
Minute(:Timestamp) < 44, 30,
45
),
If(
0 < Minute(:Timestamp) <= 15, 15,
15 < Minute(:Timestamp) <= 30, 30,
30 < Minute(:Timestamp) <= 45, 45,
0
)
)
);Re: Setting Values in a Column with ChooseThanks much, Jarmo. It worked like a charm.