Recursive CTE with partition
This would produce the expected result:
create table #demo (id int, race int, lap int)
insert into #demo values (1,21,11),(2,21,null),(3,21,null),(4,21,null),(5,29,65),(6,29,null),(7,29,null),(8,29,null);


with CTE as
(select race, ROW_NUMBER() over (partition by race  order by race) &quot;extra_lap&quot; from #demo where lap is null),
CTE2 as 
(select race, lap &quot;lap&quot; from #demo where lap is not null)
select race, lap from CTE2
union 
select CTE.race, CTE2.lap + CTE.extra_lap &quot;lap&quot; from CTE join CTE2 on CTE.race=CTE2.race

drop table #demo;