Some results:
To get the "P1" or "P2" to be the determinate factor I ended up with this:
=IF(D4=ʺP1ʺ,K3+J4,)
and in the next column:
=IF(D4=ʺP2ʺ,L2+J4,)
My deduction is that the last comma before the close bracket leaves the cell blank. If I used the "0" as in Keef's example above the I would get "0" in that cell.