Fordraiders
asked on
calculate price markup percentage divide by zero error
calculate price markup percentage
divided by zero error.
,[NetCostPerUnit] - [SellingPricePerUnit] / [NetCostPerUnit] * 100 as MarkupPercentage2
I'm running this calculation
but keep getting a error "divided by zero error."
Thanks
fordraiders
divided by zero error.
,[NetCostPerUnit] - [SellingPricePerUnit] / [NetCostPerUnit] * 100 as MarkupPercentage2
I'm running this calculation
but keep getting a error "divided by zero error."
Thanks
fordraiders
make sure the value of [NetCostPerUnit] is not zero?
try this instead:
try this instead:
case when [NetCostPerUnit] = 0 then 0 else
[NetCostPerUnit] - [SellingPricePerUnit] / [NetCostPerUnit] * 100 end as MarkupPercentage2
ASKER
ok using NetCostPerUnit as 183.66 and SellingPricePerUnit = 245.00
the markup percentage should be 33.40 I keep coming up with a negative number.
-33.40
([NetCostPerUnit] - [SellingPricePerUnit]) / nullif([NetCostPerUnit],0) * 100 as MarkupPercentage2
the markup percentage should be 33.40 I keep coming up with a negative number.
-33.40
([NetCostPerUnit] - [SellingPricePerUnit]) / nullif([NetCostPerUnit],0)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Daniel, Thanks and i need to keep the data at 2 decimals ??
Can that be done here ?
,([SellingPricePerUnit] -[NetCostPerUnit] ) / nullif([NetCostPerUnit],0) * 100 as MarkupPercentage
Can that be done here ?
,([SellingPricePerUnit] -[NetCostPerUnit] ) / nullif([NetCostPerUnit],0)
ASKER
ok, got it
cast(([SellingPricePerUnit ] -[NetCostPerUnit]) / nullif([NetCostPerUnit],0) * 100 as decimal(18,2)) as MarkupPercentage2
cast(([SellingPricePerUnit
ASKER
Thanks all !!
Open in new window