# [Libreoffice-bugs] [Bug 47023] New: Add a formula to display a value only if it's positive (or negative)

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Tue Mar 6 15:18:05 PST 2012

```https://bugs.freedesktop.org/show_bug.cgi?id=47023

Bug #: 47023
Summary: Add a formula to display a value only if it's positive
(or negative)
Classification: Unclassified
Product: LibreOffice
Version: unspecified
Platform: All
OS/Version: All
Status: UNCONFIRMED
Severity: enhancement
Priority: medium
Component: contrib
AssignedTo: libreoffice-bugs at lists.freedesktop.org

I propose that we add a formula to Calc that returns the value only if it's
positive. I've seen plenty of spreadsheets where the value of a calculation is
only useful if it's positive, otherwise it's considered to be zero. Currently,
one must use IF() functions and repeat the value being tested. I imagine that
it would look something like this:

Function IfPositive(value, Optional default)
If value > 0 Then
IfPositive = value
ElseIf IsMissing(default) Then
IfPositive = 0
Else
IfPositive = default
End If
End Function

And similarly, an IfNegative() function for anyone who may need it. A function
like this would really help to simplify these types of formulas. One example is
when calculating tax credits:

=IF(273 - IF(C1 - C2 > 0, C1 - C2, 0) * 0.04) > 0, 273 - IF(C1 - C2 > 0, C1 -
C2, 0) * 0.04), 0)

Would simplify to:

=IFPOSITIVE(273.00 - IFPOSITIVE(C1 - C2) * 0.04)

I'm not totally sure if IfPositive()/IfNegative() is the best name for this
type of function, so any comments on that would also be appreciated.

--
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
```