How to define a loop for a timeseries threshold?

Dear Knime Experts, 

Could you please help me with the question below? During a week has already tried almost everything and finally gave up.

I have a table which should be properly grouped by a certain condition: if a promotion is split by a pricelist, then these rows should be grouped by Product Name/Discount/MIN(Promo Start Date)/MAX(Promo End Date).

The main issue is that i dont know how to define a loop for a threshold in this excercise.

I know how to do this in Excel (like =IF(C2=D1+1;E1;IF(C3=D2+1;E1+1;0))), however this is gonna be applied on a huge dataset on a daily basis.

RAW Table:

Promo Start Date Promo End Date Pricelist Start Date Pricelist End Date
01.07.2015 17.07.2015 20.06.2015 17.07.2015
18.07.2015 23.07.2015 18.07.2015 14.08.2015
24.07.2015 14.08.2015 18.07.2015 14.08.2015
15.08.2015 20.08.2015 15.08.2015 18.09.2015
21.10.2016 18.11.2016 15.10.2016 18.11.2016
19.11.2016 16.12.2016 19.11.2016 16.12.2016
17.12.2016 20.01.2017 17.12.2016 20.01.2017

Desired table is looked like:

Promo Start Date Promo End Date Pricelist Start Date Pricelist End Date Flag
01.07.2015 17.07.2015 20.06.2015 17.07.2015 1
18.07.2015 23.07.2015 18.07.2015 14.08.2015 1
24.07.2015 14.08.2015 18.07.2015 14.08.2015 2
15.08.2015 20.08.2015 15.08.2015 18.09.2015 2
21.10.2016 18.11.2016 15.10.2016 18.11.2016 3
19.11.2016 16.12.2016 19.11.2016 16.12.2016 3
17.12.2016 20.01.2017 17.12.2016 20.01.2017 3

Thank you in advance!

Mikhail

Hi Mikhail,

I guess in this case the easiest way would be to use a series of lag column node and rule engine node.

Hope that helps,

Best,

Vincenzo