Hi,
I have the following problem:
a) I am generating a table (call it table dt) with mutiple columns. However I am interested to only look at specific pattern (say - "ABC@XYZ") in the col names along with two other columns (say - "LCOL", "WCOL"). I am generating that table. ( Calling that table dtB)
Next
b) I use the table dtB, pulls its column and use a for loop to generate a summary table for each such column which matches the pattern in Col Name.
c) I have created an empty table list, dt_sum_all
d) Now my goal is to obtain all the summary values of the columns which match the pattern into one table along with LCOL & WCOL column. ( I am getting N tables for N such columns, if I do not use the new table, but that is not what I want - I want 1 table)
e) Also at the end once I have a single table, I want to rename the Cols ( usually it appends SUM at the beginning of each column), like SUM (ABC@XYZ_1AS) to ABC@XYZ_1AS . Since I have many columns, I want to do it in a loop or similar.
What I have till now is the following:
dt = currentdatatable();
Wait(1);
colsd = dt << get column names( string );
pattern = "ABC@XYZ";
nd = N Items( colsd );
selCols = {"LCOL", "WCOL"};
For( i = 1, i <= nd, i++,
If( Contains( colsd[i], pattern ),
Insert Into( selCols, colsd[i] )
)
);
dtB = dt << Subset(
All rows,
Columns(selCols)
);
colNameList= dtB << get column names( string );
Wait(1);
dt_sum_all = {};
For( i = 1, i <= N Items( colNameList ), i++,
If( Contains( colNameList[i], pattern),
dt_sum = dtB << Summary(
Group( :LCOL, :WCOL ),
Sum(colNameList[i]),
Freq( "None" ),
Weight( "None" ),
) << show window(0);
);
Insert Into(dt_sum_all, dt_sum);
//Data Table (dt_sum_all) << Update (
///With(Data Table(dt_sum)),
//Match Columns(:LCOL = :LCOL, :WCOL=:WCOL)
);
////column(dt_sum, "SUM("||colNameList[i] || ")" ) << set name(colNameList[i]);
///);
The above code is not working and I am getting multiple tables for each column, instead of one merged/updated one. So not getting one table. Can anyone please help. Thanks.