Hi all. I’m running a “Date&Time Difference” node to essentially create a column that counts from a particular date in time. Everything from that date to now is negative (-1, -50, -80) and everything from before that date is positive (1, 100, 450). I know doing a math formula with abs() will turn them all into positive values. What is the best way to convert the negative values to positive and the positive values to negative. I know via the “Date&Time Difference” node I can just reverse the order in which the dates are being subtracted, but is there a rule engine or way via the nodes to do this as well?
I guess the difficulty here comes from the list of proposed functions in the -Math Formula- node which does not include the basic mathematical operators “+,-,*,/”.
The -Math Formula- node allows writing a mathematical formula as a combination of functions and basic mathematical operations. Parenthesis “(,)” to prioritize operations are also allowed. As explained in the help, one can also deal with NaN values (or missing values) with the following operators:
NaN values act as value true in boolean expressions and
compared to anything (including NaN)
in any way (including ==, but not !=,
which is like !(... == ...)) is false (0).
Moreover, there is an “if-then-else” condition which allows writing conditional mathematical operations, for instance:
if( $value$ >=0, $value$, 0)
Here the formula is for instance setting to zero any negative value. Another example here:
In the precise case of needing to change the sign of a number, @Thyme’s solution is definitely the most appropriate.
Hi, I’m new to Knime and have a question regarding how to convert certain values from + positive to - negative based on a criteria.
E.g. I want to covert personnel expenses and other operating expenses to - negative but keep net sales as + positive.
Below I’ve attached an example of my data as is - where types (net sales, other opex and personnel expenses) are located in one column and the values in another column.
My thought was to use Math formula, however I’m not sure have to write the “if formula” and target only certain values…Tnx in advance
Hi @fredrikt , for your case, since your condition is based on string, you can’t use the if(x, y, z) from the Math Formula, at least not directly. You would have to either combine this with a Rule Engine first, or do the whole thing in a Column Expressions.
Note: Make sure that your Types are written the same way (I just copied and pasted what you wrote in the thread, but your real values in your file are different - it’s not up to me to decide which of the 2 is the correct value and I won’t be diligent about it if you can’t be)
After that, a new column called “multiplier” will be created.
And then in the Math Formula, you can just apply the multiplier to the column Value: $Value$ * $multiplier$