Here's one approach:
=SUMPRODUCT((A1>IF(B1,B1*{0;1;1}+{0;0;20},{0;20;40}))*(A1-IF(B1,B1*{0;1;1}+
{0;0;20},{0;20;40}))*{12;-2;-2.5})
Does that help?