5 Replies Latest reply on Nov 13, 2012 3:06 PM by flusheddata

# How to make a calculation result default to zero if negative?

Hello all,

I would like some guidance on how to prevent a result in a calculation from being a negative number. I'm working on an inventory on hand field and I don't want the result to be able to show a negative quantity. I want it to stop at zero, or default to zero if result is less than zero.

An important note: If the result is negative, I want it to not only just show as zero, but I want it to think the result is actually zero. By this I mean if I remove an inventory item and the total quantity on hand would be -25, I don't want it to show as 0 but then act is further calculations as if it's still -25. Because then if I received 100, it would show 75 and that wouldn't be accurate. I would want it to default to zero and then act as zero in the calculation, showing a result of 100 after receiving.

Hopefully this made sense. I've played around with some functions, but I figured I'd seek some advice here. Thanks so much!

• ###### 1. Re: How to make a calculation result default to zero if negative?

= Max(YourCalcResult;0)

Kyle

• ###### 2. Re: How to make a calculation result default to zero if negative?

Kyle,

I tried the Max calculation, and while it does prevent the result from being negative and shows it as 0, it still stores the original result and treats further calculations as if it were the negative number. Like the scenario I layed out in my OP, the net result would be the 75 instead of the more accurate 100.

Is there a way around this? Thanks so much.

• ###### 3. Re: How to make a calculation result default to zero if negative?

You would use the result of the Max() function in your downstream calculations.

Kyle

• ###### 4. Re: How to make a calculation result default to zero if negative?

Assign the calculated value using a Let statement along with Kyle's Max statement.  Your result would be either 0 or a positive number.

Let(

[

MyCalcResult = my calculations

];

Max(MyCalcResult;0)

)

or, put your calculations all inline with the Max function, and simply define your field as a calc of

Max(My Calculations;0)

• ###### 5. Re: How to make a calculation result default to zero if negative?

If ( Sign ( YourCalcResult ) = -1 ; 0 ; YourCalcResult )