Rule Engine - Multiple actions under one condition

Hi community,

I have a data set that contains several projects with a potential commercialization year and the sales forecast from Year 1 to 5 for each project. For each project, year 1 will depend on the commercialization date. Therefore, it can be 2023, 2024, 2028 and so on. I want to arrange the data in columns by year, so I can have it ordered.

I thought about using rule engine node with a rule like this:

Commercialization Year = 2019 => Year 1 = 2020, Year 2 = 2021, Year 3 = 2022, Year 4 = 2023, Year 5 2024.
Commercialization Year = 2020 => Year 1 = 2021, Year 2 = 2022, Year 3 = 2023, Year 4 = 2024, Year 5 2025.

I am struggling a bit with the syntax. Any help would be highly appreciated. Also any suggestions with another node works!

Thanks

Hi @Mati_Concha , and welcome to the Knime Community.

Probably Rule Engine is not the way to go. However, I’m not sure what’s the output you are trying to get.

I can generate 5 years after the Commercial Year, but how should they be stored? As variables? In a table? Horizontal or vertical in the table? As table headers maybe?

Here’s how I generate 5 years dynamically:
image

The Commercialization Year and the Number of Forecast Years are both parameterizeable like this:
image

And it generates 5 years based on these parameters:
image

We can add the labels Year 1, Year 2, … , Year 5 after that, or Transpose horizontally, it all depends on what you want as output.

Detailing the logic/approach of the workflow:
After the parameters are set, I define a new variable for the starting year (Year 1), which is the Commercialization Year + 1:

Using the Empty Table Creator, I then generate 5 Rows for 5 years (or how many Num of Forecast Year you enter). This is controlled by the Flow Variable as follows:
image

After that, I use the Counter Generation which generates a “counter”. You can set your starting point and the scale unit in the Counter Generation, so in this case, I want to start from 2020, which is my Year 1 variable that I set earlier (Commercialization Year + 1), and I want the scale unit to be 1, that is increment by 1.

Since the Empty Table Creator created an empty table with 5 rows, the Counter Generation will generate 5 numbers, starting with Year 1 (2020) and incrementing by 1.

This is controlled by the Flow Variable like this:
image

Now, if you want to set 2020 to a variable called Year 1, 2021 to a variable called Year 2, …, 2024 to Year 5, it can be done by adding these to the original workflow:
image

I now have these variables with these values:
image

Here’s the workflow: Generate 5 years based on starting year.knwf (16.2 KB)

4 Likes

Thanks @bruno29a for the detailed explanation. It seems that is more efficient that what I did. I need the output as new variables and after that, I will unpivot those variables. I did a in-between solution with rule engine.

Close Year = Commercialization Year

$Close_Year$ = 2022 => $Sales Y1$
$Close_Year$ = 2021 => $Sales Y2$
$Close_Year$ = 2020 => $Sales Y3$
$Close_Year$ = 2019 => $Sales Y4$
$Close_Year$ = 2018 => $Sales Y5$
TRUE => 0

With this. I created variable “2022” and then created several rule engine rules to created following year. I will definitively check the solution that you proposed to have more resources to work with in the future.

Thanks for the time!

1 Like

Hello @Mati_Concha and welcome to the KNIME community.

I guess that when you talk about variables, you mean fields or columns, I’m not sure yet.

Please find this alternative workflow. Some of these nodes can help you to make easier your requested transformation.
20211105_string_years_transformation.knwf (43.0 KB)

BR

1 Like

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