AND operation in column expression

Good Day Dear Knimers :green_heart:

In this discussion @bruno29a helped me to solve problem with data comparison.

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:

  1. Created one more variable, which identifies current month (hope it identifies correctly)
  2. 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 :wink:

I have changed in the following way, but seems like my query is not working
image

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

Hello @

you can look at available functions (by category) with description in node itself:

ColumnExpressionsFunctions

Might be faster than opening a topic together with good description of your issue and then waiting for answer :wink:

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

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