[Solved] "IF" formula in Writer table

Discuss the word processor
Post Reply
Kube1989
Posts: 6
Joined: Tue Nov 08, 2022 5:22 pm

[Solved] "IF" formula in Writer table

Post by Kube1989 »

Want to look at 2 columns and if 1st is >= 2nd then 1st minus 2nd, if 1st is < then 2nd minus 1st (either returning the result)

HOWEVER- it seems in a table, formulas like to use <> instead of ()?

here's what I have:
=IF (J2>=I2;J2-I2;IF J2<I2;I2-J2) but I get "Expression is faulty"

on Windows 10...any help greatly appreciated.

Thanks!
Last edited by MrProgrammer on Mon May 15, 2023 3:09 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
Kube
OpenOffice 4.1.13
Windows 10 PRO
User avatar
keme
Volunteer
Posts: 3704
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: "IF" formula in a table using Writer

Post by keme »

So you want the absolute (positive, or "unsigned") difference between the values?

You may want to consider embedding a spreadsheet object.
  • Why use an embedded spreadsheet: Only a very limited set of functions are available to formulas in Writer tables.
  • Why continue using a table: Referencing table values in other parts of your document is easier than extracting values from embedded objects.

The IF() function you asked about is not available to Writer tables. Instead, you use a "boolean multiply" to apply conditions. The result of a compare is boolean TRUE or FALSE, numerically represented as 1 and 0, respectively.

In LibreOffice, Writer tables now support the ABS() function. In OpenOffice Writer you need a workaround.
One of several possible solutions:

Code: Select all

=(<second> - <first>) * (1 - 2 * (<first> > <second>))
Kube1989
Posts: 6
Joined: Tue Nov 08, 2022 5:22 pm

Re: "IF" formula in a table using Writer

Post by Kube1989 »

Thanks! works fantastically.

is there a way to get it to denote a negative number?
for my purpose, column 1 is my count, column 2 is their count and would prefer it to be a positive result if my count is higher and a negative if not.
Kube
OpenOffice 4.1.13
Windows 10 PRO
User avatar
keme
Volunteer
Posts: 3704
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: "IF" formula in a table using Writer

Post by keme »

Kube1989 wrote: Mon May 15, 2023 2:29 pm Thanks! works fantastically.

is there a way to get it to denote a negative number?
for my purpose, column 1 is my count, column 2 is their count and would prefer it to be a positive result if my count is higher and a negative if not.
That would be a simple subtraction.

Code: Select all

=<A2> - <B2>
Or am I missing something?
Last edited by keme on Mon May 15, 2023 3:15 pm, edited 1 time in total.
Kube1989
Posts: 6
Joined: Tue Nov 08, 2022 5:22 pm

Re: "IF" formula in a table using Writer

Post by Kube1989 »

Ahh.... I was overthinking it...
waas thinking of having to find the bigger number first THEN applying the negative after the operation....

It's a Monday :)

Thx again
Kube
OpenOffice 4.1.13
Windows 10 PRO
Post Reply