Subscribe Bookmark RSS Feed

JSL:Difference between 2 columns

vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

What if I have 2 columns with column names based on the input of data and I need to subtract them and store it in a column?

It's simple with the column name A and B and you can calculate A-B.

 

If the column name A||cyclecountvalue1 and B||cyclecountvalue2 , it gives me an error saying name unresolved.

 

Should I use associative array or complex function?

 

I really appreciate your help.

Thanks

3 REPLIES
markbailey

Staff

Joined:

Jun 23, 2011

Assuming that you actually have a data column named A||cyclecountvalue1, then this should work: Name( "A||cyclecountvalue1" ) instead. The problem is that the original column name is not a valid JSL name, but the Name() function will return a valid reference that you can use instead.

Learn it once, use it forever!
vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

cyclecount value keeps changing according to the input of the data. I don't think I can put it under the " ".

New Column( "Delta_1_"||Char(currentcycle3),
Numeric,
Formula( :Data of stack_precyc - :Data of stack_||Char(currentcycle3) )//This does not work

);

Maybe I can loop through the column one by one for both the columns till the end of the rows and calculate the difference. Can anyone help with the syntax?

Thank you
markbailey

Staff

Joined:

Jun 23, 2011

I don't recommend using formulas unless the contents of a column must automatically update in the future, after the script is finished.

You could iterate over the rows with For Each Row() function but it would be messier, I think. Instead, vectorize the problem.

You can use this pattern:

data 1 = data column 1 << Get As Matrix;

data 2 = data column 2 << Get As Matrix;

Current Data Table() << New Column( "name", Values( data 1 - data 2 ) );

Of course you would iterate over all possible pairs of columns.

Learn it once, use it forever!