# "Is it possible to fill two columns or more at the same time using column expressions?"

Hi friends.

“Is it possible to fill two columns at the same time using column expressions?”

Let’s imagine a simple scenario:

I’m using column expressions to create a calculation.
This calculation will generate the result of a “total” value per item.
Then, I will need to create another column to calculate the unit value (which would be a simple division between the total value and the quantity, resulting in the unit value).

However, since I depend on the first calculation being computed, I have to use another node to create the unit value column. In other words, I have to use two nodes.

Now comes the question: what if I use only one column expressions node, but I already create the names of the other columns, as below:

Now, imagine that in the calculation I’m setting up for the total value column, the node is iterating on the first row, at this moment the calculation finds the total value, then I save the total value in a variable and divide it by the quantity, which is also in the first row of the iteration. The result is saved in the variable and I print the variable in the other column with the name of the variable.

By doing this, I could be filling both columns at the same time, with the same node.

I’m not sure if the explanation is clear;

P.S: If it’s not possible using column expressions, is it possible to use another node for filling in multiple columns at the same time (but always in the same row of iteration) during some primary calculation?

Reason: for my project could me nice

I have played with Column Expressions node and found out that:

1. Newly create columns are unavailable on the list of columns while creating next expressions.
2. Newly created variables are unavailable on the list of variables while creating next expressions.
Thus, I would say there is nos SIMPLE way to use output of one expression as the input for the next one.

Happy KNIMEing,
Kaz

@Kazimierz is correct. Unfortunately the formulas / expressions don’t calculate in series, so you need to string together multiple Column Expressions nodes in a row to reference prior variables / calculations.

I know it is on the development radar, but they are hard at work on the new V5 browser based KNIME AP. I wouldn’t expect it to hit the top of list soon.

2 Likes

Switch to the Java Snippet node. The syntax is somewhat comparable and, if I understood your question correctly, is capable of doing this.

Example input:

You can calculate `total_value` and `unit_value` in one go and also output them simultaneously.

``````double total_value = c_para1 * c_para2;
out_unit_value =  total_value / c_qty;

out_total_value = total_value;
``````

Output:

3 Likes

Java Snippet can do some amazing things!

3 Likes

Hi friend,

Yes, what you did is exactly what I needed.
It is good to know if it is possible.

Now I’m starting to understand the power of java snippet.

1 Like

Hi Mark