Hi

Not sure if you're looking for formulae in two cells which give you the Sum of columns G & H depending on the condition, which your post implies, or if you're looking for a calculation on each row. If the former then in two separate cells:

=SUMIF(D:D,"L",H:H)-SUMIF(D:D,"L",G:G)
=SUMIF(D:D,"S",G:G)-SUMIF(D:D,"L",H:H)
If the latter you don't need a SUMIF() just use

=IF(D1="L",H1-G1,IF(D1="S",G1-H1))
HTH