BIE- How to calculate GP Margin w/ credits

This may be better accomplished by a crystal report, but I don't have access to create those.

I'm looking to calculate the final GP Margin on a job including credits which are often $0 to the customer with negative costs of goods so they greatly improve the margin. I was able to add a calculated field in BIE to get a margin on all invoice where total sold did not =0, but my credit memos where sold =0 yielded the cost of sales. Mathematically that's correct because you can't really divide by 0.

My formula is
("AR_InvoiceHistoryHeader"."TaxableSalesAmt"+"AR_InvoiceHistoryHeader"."NonTaxableSalesAmt"-"AR_InvoiceHistoryHeader"."CostOfSalesAmt")/("AR_InvoiceHistoryHeader"."TaxableSalesAmt"+"AR_InvoiceHistoryHeader"."NonTaxableSalesAmt"+1)

Thank you for any help.