The column is empty because the For() function does not return a value. Try pasting this code into the formula editor:
Local({i = N Rows(), phase = 9, MinDaysbreak = 4},
For(i, i >= Row(), i--,
If(i == N Rows(),
phase,
If(Abs(Date Difference(:"Date/Time:"n[i + 1], :"Date/Time:"n[i], "Day")) >= MinDaysbreak,
phase--,
phase
)
)
);
phase;
)
I think it will work as intended. Note these changes:
– The additional phase that sets the value of the current row (after been calculated within the For loop). Without this you get an empty column.
– To work correctly you should not iterate over all rows, only down to the current row using Row(). Otherwise you will get the same value for every row.
– You need an index for both dates to make sure to always compare with the next row. Without it is hard to predict the outcome (depends on the data).
I also defined initial i as a local parameter, but that's not necessary I think.
However, it's quite unusual to use a for loop in column formulas. If you have a large data set it can be very inefficient to loop over the table in order to set the value for every row. There are other ways to solve this problem, with column formula or JSL.
/ms