I have a dataset of measurements taken before and after a process transition for ~300 machines.

- The number of days before and after a transition varies
- The transition can happen on different Days
I inserted a formula that would label 3 days on either side of a transition day so I can select an idendical sample size for each of the 300 machines.
If(
Lag( :Condition, -3 ) == "Transition", "1",
Lag( :Condition, -2 ) == "Transition", "2",
Lag( :Condition, -1 ) == "Transition", "3",
:Condition == "Transition", "Transition",
Lag( :Condition, 1 ) == "Transition", "4",
Lag( :Condition, 2 ) == "Transition", "5",
Lag( :Condition, 3 ) == "Transition", "6"
)
Which gives what I was hoping for

Using if statements like that feels...hacky. Can anyone think of a more elegant way to do this?