Hi everyone, I have a script that creates new numerical columns for any columns that has very small values (i.e. transform a column that has unit meters into mm or µm for better readability).
It seemed to be working fine; the columns were generated without issue. But then I got some issues later on when joining with other tables, suddenly the columns showed no data anymore. When I check the formula in the new columns I see that instead of the name of the source column, it has a colnames[i] reference from the loop in the script (see screenshot).
Names Default To Here( 1 );
dt = Current Data Table();
colnames = dt << get column names( numeric, string );
For( i = 1, i <= N Items( colnames ), i++,
If( (Col Max( column(dt,colnames[i]))-Col Min( column(dt,colnames[i])))<1e-4 & (Col Max( column(dt,colnames[i]))-Col Min( column(dt,colnames[i])))>0,
If( !Contains( colnames, colnames[i] || "_µm"),
dt << New Column( colnames[i] || "_µm", Formula( As Column( colnames[i] ) * 1e6 ) ) )
,
If( (Col Max( column(dt,colnames[i]))-Col Min( column(dt,colnames[i])))<1e-1 & (Col Max( column(dt,colnames[i]))-Col Min( column(dt,colnames[i])))>1e-4,
If( !Contains( colnames, colnames[i] || "mm"),
dt<<New Column(colnames[i]||"_mm",Formula(As Column(colnames[i])*1e3)))
)
),
);