Hi @Michellehml , I went back to your first post to understand what you are trying to do (and it does look like you are trying to do a sum). And welcome to the Knime Community.
You can do this in the Math Formula, since you are dealing with numbers, and the Math Formula does offer the ability to use if condition. However, like almost all nodes, the result of one Math Formula node will be for one column, and since you are modifying 2 columns (your initial rules are incomplete: see the clarified version below), you will need 2 Math Formula. The Column Expression node would allow you to do both in the same node, however, you would still need to duplicate the same rules.
I’ll do both versions for you. Before this, however, I want to clarify the rules:
If Day of the month > 23:
ATS WK 5 = ATS WK4 + ATS WK5
ATS WK 4 = 0 (this is not specified, but is demonstrated in your output)
else (that is if Day of the month <= 23):
No change in either column
The workflow with both methods looks like this:
Input data (same as yours):
Let’s look at the Math Formula method:
I first process the ATS WK 5, since I need the original value of ATS WK 4 (If I process ATS WK 4 first, I will lose its original value since processing ATS WK 4 means setting it to 0).
The Expression for this is:
if($Day of the month$ > 23, $ATS WK 4$ + $ATS WK 5$, $ATS WK 5$)
This means if $Day of the month$ > 23
, set value to $ATS WK 4$ + $ATS WK 5$
, otherwise keep the same value of $ATS WK 5$
(don’t forget that we are processing the column $ATS WK 5$ here)
So, at this point, ATS WK 5
has been processed and we can see the results
Now we process ATS WK 4
, so onto the next Math Formula:
if($Day of the month$ > 23, 0, $ATS WK 4$)
Similarly, this is saying if $Day of the month$ > 23
, set value to 0, otherwise keep $ATS WK 4$
as is.
Final results:
Let’s look at the Column Expression now:
As you can see, I have 2 expressions defined. The screenshot is showing the process for ATS WK 5:
if(column("Day of the month") > 23) {
column("ATS WK 4") + column("ATS WK 5")
} else {
column("ATS WK 5")
}
This translate to the same thing as what we did in the Math Formula. If Day of the month > 23
then set value to ATS WK 4 + ATS WK 5
, otherwise leave as ATS WK 5
And I’m making sure that the respective expression is replacing its respective column:
And here’s the expression for ATS WK 4
:
if(column("Day of the month") > 23) {
0
} else {
column("ATS WK 4")
}
Final result:
Here’s the workflow: math formula with conditions.knwf (9.5 KB)
Note: I know you mentioned that you don’t have the Column Expression and you are struggling to download it. By opening my workflow, Knime should offer you to automatically download and install the proper version of Column Expression for your Knime version.