Math operarions on ALL cells

Hi All,

I would like to perform the same math operation on all cells on the table (I want to multiply all values by -1). I've tried to do it via column loop and math node, but math node seems not support flow variables (ie: flow_variable * -1).

Can you give me any tips how to accomplish this task?

 

Regards,

Filip

Unfortunately the Math node does not support variables nor arrays at the moment, but the Java Snippet does (I hope you are familiar with Java, otherwise you could also use Perl, Jpython, or R). To use the Java Snippet, you need to create a collection/array of cells using the Collection Creator Column node. With this go into the Java Snippet and enter the following script:

Double product = null;
Double[] array = $AggregatedValues$;
for (int i = 0; i < array.length; i++) {
  if (i == 0) {
    product = array[i];
  } else {
    product *= array[i];
  }
}
if (product == null) {
  return null; // which is a missing value
}
return product;

Hi Gabriel,

Thanks for the answer, I will try this method,

Filip