Bug 47023 - Add a formula to display a value only if it's positive (or negative)
Summary: Add a formula to display a value only if it's positive (or negative)
Status: RESOLVED WONTFIX
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: contrib (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-06 15:18 UTC by Adam Fabicki
Modified: 2012-03-09 21:32 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Fabicki 2012-03-06 15:18:05 UTC
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.
Comment 1 Adam Fabicki 2012-03-09 21:32:41 UTC
Just realized this is the same thing as the MAX() formula.