cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Azim
Level II

Column Header Ordering

After transposing data table, 

 

Data Table( "Overall" ) << Transpose(
	columns( :Value),
	By( :Department, :Resource, :Chart ),
	Label( :Date),
	Output Table( "report overall" )
);

My headers which is presented by date is no longer in order. Which I then have to mannually drag and drop to have it fixed. Luckily it only involves 7-8 columns. Nontheless, doing so eats up my time which I do not initially have to. 

Azim_1-1729242963544.png

 

 

Is there a way to make it in order as shown in picture? 

Azim_0-1729242726856.png

Those dates will change daily as my fixed date range is 7 days.

set_date = Today();

date_min = (set_date - In Days(7));

Data Table("Overall") << Select where (:date < date_min) << Delete Rows;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Column Header Ordering

Here is a script that will reorder the columns as you requested

Names Default To Here( 1 );

// Example table to use for illustration
New Table( "Example",
	Add Rows( 0 ),
	New Column( "Department", Character, "Nominal" ),
	New Column( "Resource", Character, "Nominal" ),
	New Column( "Chart", Character, "Nominal", Set Selected ),
	New Column( "17/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "16/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "15/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "11/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "14/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "18/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "13/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "12/10/2024", Numeric, "Continuous", Format( "Best", 12 ) )
);
Wait( 5 );

// This JSL with properly reorder the data table
dt = Current Data Table();

colNames = dt << get column names( string );

For Each( {col}, colNames,
	If( Is Missing( Try( Num( Informat( col, "d/m/y" ) ) ) ) == 0,
		Column( dt, col ) << set name( Char( Num( Informat( col, "d/m/y" ) ) ) ),
		Column( dt, col ) << set name( "0" || col )
	)
);
// Reorder columns by name
dt << Reorder by Name;

colNames = dt << get column names( string );

For Each( {col}, colNames,
	If( Is Missing( Num( col ) ) == 0,
		Column( dt, col ) << set name( Format( Num( col ), "d/m/y" ) ),
		Column( dt, col ) << set name( Substr( col, 2 ) )
	)
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Column Header Ordering

Here is a script that will reorder the columns as you requested

Names Default To Here( 1 );

// Example table to use for illustration
New Table( "Example",
	Add Rows( 0 ),
	New Column( "Department", Character, "Nominal" ),
	New Column( "Resource", Character, "Nominal" ),
	New Column( "Chart", Character, "Nominal", Set Selected ),
	New Column( "17/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "16/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "15/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "11/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "14/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "18/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "13/10/2024", Numeric, "Continuous", Format( "Best", 12 ) ),
	New Column( "12/10/2024", Numeric, "Continuous", Format( "Best", 12 ) )
);
Wait( 5 );

// This JSL with properly reorder the data table
dt = Current Data Table();

colNames = dt << get column names( string );

For Each( {col}, colNames,
	If( Is Missing( Try( Num( Informat( col, "d/m/y" ) ) ) ) == 0,
		Column( dt, col ) << set name( Char( Num( Informat( col, "d/m/y" ) ) ) ),
		Column( dt, col ) << set name( "0" || col )
	)
);
// Reorder columns by name
dt << Reorder by Name;

colNames = dt << get column names( string );

For Each( {col}, colNames,
	If( Is Missing( Num( col ) ) == 0,
		Column( dt, col ) << set name( Format( Num( col ), "d/m/y" ) ),
		Column( dt, col ) << set name( Substr( col, 2 ) )
	)
);
Jim
Azim
Level II

Re: Column Header Ordering

Works great! Thanks!