As I don't have your data table this is just a guess
Names Default To Here(1);
dt = New Table("Untitled 2",
Add Rows(23),
Compress File When Saved(1),
New Column("S",
Character,
"Nominal",
Set Values(
{"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "B", "B", "B", "C", "C"}
)
)
);
dt << New Column("R", Numeric, Continuous, Formula(
If(:S == "A" & Lag(:S, -6) != "A",
99
, :S == "A",
Lag(:R)
);
));
You can use Lag to look for values behind and also forward.
-Jarmo