- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Stack column using table variable list
I would like to stack a list of columns based on a table variable, but I'm having trouble figuring out how to format the variable and the script
//this is my table variable -- I've called it myList
{"colName1", "colName2"}
//this is my script
dt = Current Data Table();
dt << Stack(
columns(myList),
Output Table( "New Table" )
);
I have a table with column names colName1, colName2, colName3...
And I would like to be able to stack only certain columns based on a table variable list. I've been able to do this by grouping columns then stacking the whole group, but I've run into situations where I may want to stack a subset of a group of columns, hence this attempt.
The list and script above gives me the error: "Column not found in access or evaluation of bad argument"
I've also tried changing the command to
columns(eval(myList))
but that gives me the same error
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Stack column using table variable list
Taking a hint from this thread, I figured out that using the Parse() command works for this.
Table variable myList formatted as such:
{"colName1","colName2"}
and script looks like this:
dt = Current Data Table();
dt << Stack
( columns( Parse(myList) ),
Output Table( "Stacked Data" )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Stack column using table variable list
@snapnpop ,
Shouldn't your table variable look like this ?
{"Column1", "Column2"} vs {"Column1, Column2"} ?
Uday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Stack column using table variable list
I've fixed my original post. My table variable was as you typed out.
I had also tried:
("colName1","colName1")
Both with the same errors
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Stack column using table variable list
hello,
you can try with this code
dt = current data table();
// column dialog editor
cd = Column Dialog(
Var = collist( " select columns >>", MinCol( 1 ) ), Hlist( "" ), );
collist= cd["Var"];
//stack operation
dt_stack = dt << Stack(
columns( collist ), Output Table( "STacked" ),
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Stack column using table variable list
My goal is to have a table variable with a list of column names to stack, then run a script that utilizes that variable.
The intent is to be able to edit the variable to add/remove columns to be stacked, as the dataset expands/contracts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Stack column using table variable list
Taking a hint from this thread, I figured out that using the Parse() command works for this.
Table variable myList formatted as such:
{"colName1","colName2"}
and script looks like this:
dt = Current Data Table();
dt << Stack
( columns( Parse(myList) ),
Output Table( "Stacked Data" )
);