Choose Language Hide Translation Bar
Highlighted
joshua
Level II

Concanate rows in groups and show them in another column (JSL way prefferred)

Hi,

 

Let's say we have data like this and want to create a new column that in each team concrete these rows.

 

joshua_0-1588289432091.png

How this can be done in jsl ? Assuming for loop needed to go each row in unique Colum2 and call those rows ?

Attached this data table.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
gzmorgan0
Super User

Re: Concanate rows in groups and show them in another column (JSL way prefferred)

@joshua , try this script.

Names Default to Here(1);

//create data table
dt = New Table( "Team_table",
	Add Rows( 5 ),
	Set Header Height( 46 ),
	New Column( "A",
		Character( 6 ),
		"Nominal",
		Set Values( {"Bob", "Mike", "David", "Hellen", "Karen"} ),
		Set Display Width( 63 )
	),
	New Column( "Column 2",
		Character( 5 ),
		"Nominal",
		Set Values( {"TeamA", "TeamA", "TeamA", "TeamB", "TeamB"} ),
		Set Display Width( 63 )
	),
	New Column( "Column 3",
		Character,
		"Nominal",
		Set Values(
			{"Bob | Mike | David", "Bob | Mike | David", "Bob | Mike | David",
			"Hellen | Karen", "Hellen | Karen"}
		),
		Set Display Width( 106 )
	)
);

// make a list of groups
summarize( grp = by(:Column 2));  //grp = {"TeamA", "TeamB"}

newcol = dt << New Column("Team Members", character);

For(i=1, i<=nitems(grp), i++,
   rowid = dt << get rows where(:Column 2 == grp[i] );
   str =  concat items(dt:A[rowid], " | ");	
   newcol[rowid] = str
);

View solution in original post

1 REPLY 1
Highlighted
gzmorgan0
Super User

Re: Concanate rows in groups and show them in another column (JSL way prefferred)

@joshua , try this script.

Names Default to Here(1);

//create data table
dt = New Table( "Team_table",
	Add Rows( 5 ),
	Set Header Height( 46 ),
	New Column( "A",
		Character( 6 ),
		"Nominal",
		Set Values( {"Bob", "Mike", "David", "Hellen", "Karen"} ),
		Set Display Width( 63 )
	),
	New Column( "Column 2",
		Character( 5 ),
		"Nominal",
		Set Values( {"TeamA", "TeamA", "TeamA", "TeamB", "TeamB"} ),
		Set Display Width( 63 )
	),
	New Column( "Column 3",
		Character,
		"Nominal",
		Set Values(
			{"Bob | Mike | David", "Bob | Mike | David", "Bob | Mike | David",
			"Hellen | Karen", "Hellen | Karen"}
		),
		Set Display Width( 106 )
	)
);

// make a list of groups
summarize( grp = by(:Column 2));  //grp = {"TeamA", "TeamB"}

newcol = dt << New Column("Team Members", character);

For(i=1, i<=nitems(grp), i++,
   rowid = dt << get rows where(:Column 2 == grp[i] );
   str =  concat items(dt:A[rowid], " | ");	
   newcol[rowid] = str
);

View solution in original post

Article Labels

    There are no labels assigned to this post.