Choose Language Hide Translation Bar
Highlighted
bbass
Level I

Adding variable column names based on date

I want to create a script that adds multiple columns with the column names based on the date.  For example, taking today's date "3/4/2020" and adding 3 additional columns whose names correspond to the previous 3 weeks; giving the result of:

 

Column 1: "3/4/2020"

Column 2: "2/26/2020"

Column 3: "2/19/2020"

Column 4: "2/12/2020"

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Adding variable column names based on date

Here is a real simple way to do this.  It takes the first column in the data table and sets it equal to today's date, and then on the next three columns it sets to dates 1,2,& 3 weeks before

Names Default To Here( 1 );
dt = Current Data Table();

Column( 1 ) << set name( Format( Today(), "m/d/y" ) );
Column( 2 ) << set name( Format( Today() - In Weeks( 1 ), "m/d/y" ) );
Column( 3 ) << set name( Format( Today() - In Weeks( 2 ), "m/d/y" ) );
Column( 4 ) << set name( Format( Today() - In Weeks( 3 ), "m/d/y" ) );

 

Jim

View solution in original post

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Adding variable column names based on date

Here is a real simple way to do this.  It takes the first column in the data table and sets it equal to today's date, and then on the next three columns it sets to dates 1,2,& 3 weeks before

Names Default To Here( 1 );
dt = Current Data Table();

Column( 1 ) << set name( Format( Today(), "m/d/y" ) );
Column( 2 ) << set name( Format( Today() - In Weeks( 1 ), "m/d/y" ) );
Column( 3 ) << set name( Format( Today() - In Weeks( 2 ), "m/d/y" ) );
Column( 4 ) << set name( Format( Today() - In Weeks( 3 ), "m/d/y" ) );

 

Jim

View solution in original post

Highlighted
bbass
Level I

Re: Adding variable column names based on date

That worked.  Thanks!

Article Labels

    There are no labels assigned to this post.