[Solved] cell comparison inside IF() test

Discuss the spreadsheet application
Post Reply
gramb0t
Posts: 2
Joined: Thu Oct 17, 2019 8:38 pm

[Solved] cell comparison inside IF() test

Post by gramb0t »

Hello Everyone!
Long time lurker first time caller.
Hows everybody feeling today? Alllllllrighty then.

I have a questions, goes a little like this:

If a_cell minus 180 is less than 0, show a 0, if not, show what the difference is.

currently my formula looks like this:
=IF((J34-180) < 0; "0"; (J34-180));

For fun, lets assume the following:
J34 = 190

In a perfect world, the result would be 10,
=IF((190-180) < 0; "0"; (190-180));
=IF((10) < 0; "0"; (10))
=10

alas, she left,
the dogs gone,
and all i have is an Err:509 in that cell.

Anyone have an idea on whats causing that?
Last edited by MrProgrammer on Fri Oct 18, 2019 4:48 am, edited 1 time in total.
Reason: Tagged ✓ [Solved]
OpenOffice 4.1.7 on OSx Mojave (10.14.6)
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: cell comparison inside IF() test

Post by Lupp »

-1- I would see it as a bad idea to return the result in case of a negative difference as the TEXT "0". It should be the number 0.
-2- The simplest formula for the purpose is

Code: Select all

=MAX(0; Minuend - Subtrahend)
or, for one of your examples

Code: Select all

=MAX(0; J34-180)
-3- Error code 509 is explained as "Missing operator". This may be slightly misleading here. In fact the error is caused by the trailing semicolon.
-4- Many of the pairs of parentheses don't do anything.
Last edited by Lupp on Thu Oct 17, 2019 9:52 pm, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: cell comparison inside IF() test

Post by Zizi64 »

509
Missing operator
Operator is missing, for example, "=2(3+4) * ", where the operator between "2" and "(" is missing.
Please upload your .ods type sample file here.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
gramb0t
Posts: 2
Joined: Thu Oct 17, 2019 8:38 pm

Re: cell comparison inside IF() test

Post by gramb0t »

@Lupp - Thanks for that, that formula worked great.
I've spent a little too much time complicating things in life, it seems like that was one of them too.
OpenOffice 4.1.7 on OSx Mojave (10.14.6)
Post Reply