Please try again, note the Offset OFFSET(M13,ROW(M1:M260),))
Data start at M14
=INDEX(M14:M260,MATCH(1,INDEX(SUBTOTAL(2,OFFSET(M13,ROW(M1:M260),)),),))-INDEX(M14:M260,MATCH(1,INDEX(1/SUBTOTAL(2,OFFSET(M13,ROW(M1:M260),)),)))
=INDEX(M14:M260;EQUIV(1;INDEX(SOUS.TOTAL(2;DECALER(M13;LIGNE(M1:M260); )); ); ))-INDEX(M14:M260;EQUIV(1;INDEX(1/SOUS.TOTAL(2;DECALER(M13;LIGNE(M1:M260); )); )))