I am trying to use if statement in Column Expression Node and now I have faced some problem with this statement.
When I am comparing two data, it is not giving a right answer. Maybe the way how I am writing an expression is not right enough
Can you look at this, pleaseā¦
There are my screenshots:
I am comparing two data, if they are equal it should set āCurrentā
The output:
When I tried to use with Rule Engine, it worked finely. But rule engine does not support some math operations as I know. Taking difference from some data
EDIT: Additional info, as you know, the Column Expressions is based on Javascript. In js, you can compare if date1 > date2 or if date1 < date2, but not if date1 is equal to date2, at least not directly as you found out with your issue.
Hereās a quick test. I added this expression as a new column:
var date1 = new Date(column("compare_filedate"));
var date2 = new Date(column("compare_red_year_month"));
if(date1 > date2) {
"Greater"
} else if (date2 > date1) {
"Less"
} else {
"Same"
}
Results:
As you can see, it has no problem detecting that date1 > date2 or date1 < date2. The only way I could get the results where the 2 dates are the same is basically the default case if none of the 2 conditions are true (date1 > date2 or date1 < date2), which would by default means they are equal.
So, another way to do this without converting to string would be:
var date1 = new Date(column("compare_filedate"));
var date2 = new Date(column("compare_red_year_month"));
if(!(date1 > date2 || date2 > date1)) {
"Current"
}
Sorry, one more question
Column expression it is from Knime Lab, is it ok if I use all the time? I know that nodes which are in Labs, havent deployed it. I mean wont be there are some bugs?
Personally, I really like this nodeā¦ All operations in one node