Script only works when run step-by-stepNames Default to Here(1);
Query = current data table();
Query_piv = (Data Table( "SO Query" ) << Tabulate(
Add Table(
Column Table(
Grouping Columns( :Year, :Week ),
Analysis Columns( :QTY Ordered )
),
Row Table(
Grouping Columns( :Item, :Item Description, :Channel, :Product Type )
)
)
));
Query_tab = Query_piv << Make Into Data Table;
Query_piv << close window;
Col_Start = 5;
Query_tab << group columns("Weeks",column(Col_Start), N cols(Query_tab) - Col_Start + 1);
Col_group = Query_tab << get column group ("Weeks");
Query_stack = Query_tab << Stack(
columns( Column Group( "Weeks" ) ),
Output Table( "Stacked History" )
);
I have a set of data (weekly order volume) that I'm tabulating and then stacking. This script works fine if I run it pieces at a time. However, when I try to execute it as a whole I get the following error. Any ideas?

Automation and ScriptingRe: Script only works when run step-by-steptry
Query_tab = Query_piv << Make Into Data Table;
wait(0);
Re: Script only works when run step-by-stepI tried wait there.. I also tried it after Col_start = 5. No luck.
Re: Script only works when run step-by-stepHmm, I cannot reproduce the issue with some dummy data. It might be a timing issue, but why doesn't wait(0) work?
You could skip the grouping step and use the column references directly as input for Stack.
Remove from() to start with column #5.
Query_tab = obj << Make Into Data Table;
cols = Query_tab << get column references;
Remove From( cols, 1, 4 );
Query_tab << Stack( columns( cols ) ) ;
Re: Script only works when run step-by-stepHow big starting table you have? How big tabulate do you end up with? Does the script work properly if use values instead of variables with the group columns?
You could try adding data table reference to Column instead of relying on current data table, so use
Column(Query_tab, Col_Start)
Also if Data Table("SO Query") is same as Query = Current Data Table(), I would replace it with dt to make it more robust.
Re: Script only works when run step-by-stepAdding the table reference solved the problem. Thanks!!