I'm not sure if I have understood correctly, but here's an alternative. If it's what you want, you also need to see how well it will scale.
NamesDefaultToHere(1);
// Example table . . .
dt = New Table( "Inspection",
Add Rows( 10 ),
New Column( "ID",
Character,
"Nominal",
Set Values(
{"101", "101", "101", "101", "102", "102", "102", "101", "101", "101"}
)
),
New Column( "Last Inspection Decision",
Character,
"Nominal",
Set Values( {"", "", "", "VAI", "", "", "Code 1", "", "", "Code 2"} )
),
New Column( "Last Inspection Data",
Character,
"Nominal",
Set Values(
{"PRODUCT SPECIFICATIONS DEFECT", "CGMP Deviations", "21 CFR 211.113",
"LIQ_US", "PRODUCT SPECIFICATIONS DEFECT", "21 CFR 211.113", "LIQ_US",
"PRODUCT SPECIFICATIONS DEFECT", "CGMP Deviations", "21 CFR 211.113"}
)
)
);
// Copy the table
dt2 = Eval(dt << getScript);
dt2 << setName(dt << getName ||" Stacked");
// Get the values from the two columns of interest into lists
ids = Column(dt2, "ID") << getValues;
vals = Column(dt2, "Last Inspection Data") << getValues;
// Find out where we need to insert new values, get the required values, and insert them into the right positions
insertAfter = dt2 << getRowsWhere(!IsMissing(:Last Inspection Decision));
for(r=1, r<= NItems(insertAfter), r++,
InsertInto(ids, Column(dt2, "ID")[insertAfter[r]], insertAfter[r] + r);
InsertInto(vals, Column(dt2, "Last Inspection Decision")[insertAfter[r]], insertAfter[r] + r);
);
// Add rows to teh copy of the table, insert the column values, and delete the column we don't need
dt2 << addRows(NRows(insertAfter));
Column(dt2, "ID") << setValues(ids);
Column(dt2, "Last Inspection Data") << setValues(vals);
dt2 << deleteColumns(:Last Inspection Decision);