For cases like this I often use Summary followed by Update (Tables menu).
Make a Summary table with mean of Data (grouped by Target, Cell & Data Order), delete rows except for Target = D, and updade the original with the summary table (match by columns Cell and Data Order).
If you need a dynamic solution it is possible with a Column Formula, however they can get quite complex. This formula should work for your example table:
:Data - If(:Target == "D",
Col Mean(:Data, :DataOrder, :Target == "D"),
(Col Sum(:Data, :Cell, :DataOrder) - Col Sum(:Data, :Cell, :DataOrder, :Target == "D")) / (
Col Number(:Data, :Cell, :DataOrder) - Col Number(:Data, :Cell, :DataOrder, :Target == "D"))
);