I do not have 365 but try

=IFS(D2=0,C2,D2<>0,D2,AND(B3="Active",D3=0),D3,TRUE,C3)