I’m having some issues with creating a calculated field that subtracts an InvoiceAmt from any MiscCharges with a “SHIP” Code attached to it.
So say there’s an invoice with 2 Misc Charges on it, one for “TAX” and one for “SHIP”; I want the calculated field to subtract only the “SHIP” MiscAmt from the InvoiceAmt.
As of right now, I have this: case when InvcMisc.MiscCode = 'SHIP' then InvcHead.InvoiceAmt - InvcMisc.MiscAmt else '0.00' end
Which works only when the invoice has one “SHIP” on it… If the invoice has several lines with a “SHIP” Misc Charge on it then it doesn’t work… I thought since it’s not adding the “SHIP” Misc charges together, it needs a SUM… So I tried: (case when InvcMisc.MiscCode = 'SHIP' then sum(InvcMisc.MiscAmt) else '0.00' end)
but that ends up summing all the Misc Charge amounts. (and obviously not using InvoiceAmt at all)
So I basically need something like this: case when InvcMisc.MiscCode = 'SHIP' then (InvcHead.InvoiceAmt - sum(ONLY 'SHIP' InvcMisc.MiscAmts) else '0.00' end
Any help would be appreciated.