Adjust number column if string column contains a specific value

Hi there! I have a relatively simple problem but I cannot find a way to solve it. I have a simple data set of amounts and then their types - debit or credit. I need the output to multiply all debit amounts by -1.
Rule Engine cannot have a mathematical operation as its result (I tried Type LIKE β€œD” => Amount*(-1) sadly), and Math Formula cannot reference string columns.

Input Example:
Amount | Type
100 | C
200 | D
300 | D
400 | C

Expected Outcome:
Amount | Type
100 | C
-200 | D
-300 | D
400 | C

One more thing. Yes, I could filter the original input at the beginning to separate D and C and then just use Math Formula to multiply the D β€œline”, and then Concatenate everything back.
However, in reality, my input file is a bit bigger with more columns which I also filter by various types and then make various calculations. Everything is done with amount being positive number, but I was wondering if I can change the debits to negatives at the end. Thanks!

Hello @ieva06,

and welcome to KNIME Community!

Usually approach is to use Rule Engine node to create new column depending on condition column (Type) populated with values needed for mathematical operation (1 or -1). Math operation (multiplication) is then done with Math Formula node.

For a one node solution there is Column Expressions node which features if else syntax and supports various operations/manipulations. See this example:



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.