Good Day Dear Knimers
In this discussion @bruno29a helped me to solve problem with data comparison.
Good Day Knimers
I have an issue, where I need to compare data with next year (2022).
The formula as in here
if( year(date(date#( “Time Period”,‘MMM YYYY’),‘YYYY/MM’))=’$(vNextYear)’ , “Consensus Selling Forecast (N-1)”,’’) as “NextYear N-1 Consensus Selling Forecast”,
in which vNextYear = Year(Today()) + 1;
I have done in the following way:
Added Create Date&Time Range Node and wanted to cross join with my initial data. But, unfortunately, it did not go well, because my…
Now I have almost the same problem, but here I have to compare data (month and year) with current month and year. For that I have done the following:
Created one more variable, which identifies current month (hope it identifies correctly)
Added if statement in order to compare year and month
The problem is that I could not add and operation in column expression.
currentMonth = new Date().getMonth();
currentYear = new Date().getFullYear();
timePeriodYear = substr(column("Time Period"), 0, 4);
timePeriodMonth= substr(column("Time Period"), 5, 2);
if((currentYear==timePeriodYear) and (currentMonth==timePeriodMonth)) {
column("Consensus Selling Forcase (N-1)")
}
So, in general my formula looks like this:
if( date(date#( "Time Period",'MMM YYYY'),'YYYY/MM')>='$(vToday)',
"FY(Full Year) Consensus Selling Qty",'') as "YTG Consensus Selling Qty",
if( date(date#( "Time Period",'MMM YYYY'),'YYYY/MM')<'$(vToday)',
"FY(Full Year) Consensus Selling Qty",'') as "YTD Consensus Selling Qty",
where vToday is
vToday = Date(Today(),‘YYYY/MM’);
Can you please help me to solve this issue?
So, I have to compare current month and year with time period(month and year)
Many thanks,
Karlygash
I have changed in the following way, but seems like my query is not working
currentYear = new Date().getFullYear();
currentMonth = new Date().getMonth();
manipulatedMonth = toInt(currentMonth)+1;
timePeriodYear = toInt(substr(column("Time Period"), 0, 4));
timePeriodMonth= toInt(substr(column("Time Period"), 5, 2));
if((currentYear>=timePeriodYear) || (manipulatedMonth>=timePeriodMonth)) {
column("FY(Full Year) Consensus Selling Qty")
}
}
As you can see, it is taking value for august as well
Hi @Karlygash , you can use &&
for doing AND. The ||
is doing an OR, so it’s not the same logic.
4 Likes
ipazin
September 15, 2021, 12:02pm
4
Hello @
you can look at available functions (by category) with description in node itself:
Might be faster than opening a topic together with good description of your issue and then waiting for answer
Br,
Ivan
5 Likes
thanks, @bruno29a and @ipazin
I have added && to my condition, but here are some issue
currentYear = new Date().getFullYear();
currentMonth = new Date().getMonth();
manipulatedMonth = toInt(currentMonth)+1;
timePeriodYear = toInt(substr(column("Time Period"), 0, 4));
timePeriodMonth= toInt(substr(column("Time Period"), 5, 2));
if((timePeriodYear>=currentYear) && (timePeriodMonth>=manipulatedMonth)) {
column("FY(Full Year) Consensus Selling Qty")
}
In the output, I am not getting column(“FY(Full Year) Consensus Selling Qty”), instead I am getting month))
Hi @Karlygash ,
This is because you don’t have an else
statement.
So, when the if statement is not true, Knime needs a default value, which would usually be defined in the else
statement. If there is no else statement, it will take the last defined value, which in your case is timePeriodMonth= toInt(substr(column("Time Period"), 5, 2));
, which is basically the month value.
Define a default value in an else
statement, and you will be able to control this.
2 Likes
system
Closed
September 22, 2021, 6:16pm
7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.