Column Expression node

Hi Team,

As I am new to knime I am facing an error while using IF Else condition with AND and OR logical operators.

Please correct the code

IF [PO Price per PC]>=(([Std Cost per DZ]/12)-1)
AND column([PO Price per PC])<=(([Std Cost per DZ]/12)+1)

OR isMissing([Std Cost per DZ])

THEN “Current Qtr”

//Elseif [PO Price per PC]>=(([Std Cost per DZ]/12)-1)
//AND [PO Price per PC]<=(([Std Cost per DZ]/12)+1)

//then “Previous Qtr”

//ELSE “Current Qtr”

ELSE “”

ENDIF

Thanks,
Subash

Hi @Subramanyam

What is wrong with this expression…?

How does your input looks like? And what is the output that you expect? What is the error / miscalculation ?

Please come up with a dataset.

gr. Hans

3 Likes

Maybe double check that your calculations are being pointed toward columns that are number data types instead of strings? Always easier to share an example workflow with dummy data that highlights your issue.

2 Likes

Agreeing with @HansS and @iCFO that providing a sample dataset/workflow and a description of what you are wanting to do is more likely to help people to help you than simply supplying some code (in “some other language”).

It looks like you are trying to use Alteryx code (I’m guessing) which does not use the same scripting language as Column Expressions.

The Column Expressions node scripts are based on javascript, so you may wish to acquaint yourself with some basic javascript from a tutorial site such as this:

Also, take a look at the examples in the following forum post which may give some pointers:

Hopefully bringing that information together will help point you in the right direction.

All that being said… AI can be quite good for giving a quick-start with code conversions. For example, chatGPT suggested the following conversion, so you could give it a try with your dataset and come back with further questions if it still isn’t working.

if (
  column("PO Price per PC") >= (column("Std Cost per DZ") / 12 - 1) &&
  column("PO Price per PC") <= (column("Std Cost per DZ") / 12 + 1)
  || isMissing(column("Std Cost per DZ"))
) {
  "Current Qtr"
} else {
  ""
}
4 Likes

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