# if statement with math calculation

Hi - very new to knime, any idea how I would complete the following combination of steps with multiple nodes? I also wonder if there is a node to store calculation results for step 1 and 2? Just so I can add logic to compare the two results and manipulate from there.

1. filter price = 1, sum the quantities (in this case 11), multiply the sum by 10. (in this case 110)
2. Filter price = 2, sum the quantity (in this case 110)
3. If step 1 = step 2, delete rows where price = 1

Price Quantity
1 2
1 5
1 4
3 32
2 50
2 40
2 20

Look at Column Expression node. In step 3 what do you mean sum in step 1 = sum in step 2 or something else?

1 Like

Hi,
You can calculate step 1 and step 2 by â€śMath Formulaâ€ť node (separately). Then you can use â€śRule-based Row Filterâ€ť node to use the conditions (step 1 = step 2 and price = 1) to filter the rows.

1 Like

yes so in step 3, if in step 1 (the sum of quantity at price 1 [(2+5+4)*10]) equals step 2 (sum of quantity at price 2 [50+40+20]) then delete all rows with price = 1.

so in this case step 1 = 110, and step 2 = 110, so we would delete the rows where price=1

I would add flag column for lines to be compared using Rule Engine with Append Column
IF Price = 1 => True
IF Price = 2 => True
Then use Group by node grouping by New and Sum columns choose max option in Manual Aggregation for price column.

how do you do it with mixed column types?
Iâ€™m trying this logic:
if season = â€śspringâ€ť then day_of_year - 79,
but in Rule engine it doesnâ€™t seem to accept expressions, and Math node works only with numbers.

You can try

node. It may need to be installed first.

2 Likes