[Solved] Nested conditionals with OR
[Solved] Nested conditionals with OR
Hi,
I'm having great difficulty nesting these conditionals. The first conditional works on its own but when I try to add the second I get Err 504 or 509. I am a beginner, so no doubt I'm making some elementary error. Can anyone point it out out to me, please ?
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";"SOURCE?";IF(OR(C214={"amazon";"tesco"});"1476";"SOURCE?")) gives Err 504
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";"SOURCE?");IF(OR(C214={"amazon";"tesco"});"1476";"SOURCE?") gives Err 509
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";"SOURCE?" works OK
I'm having great difficulty nesting these conditionals. The first conditional works on its own but when I try to add the second I get Err 504 or 509. I am a beginner, so no doubt I'm making some elementary error. Can anyone point it out out to me, please ?
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";"SOURCE?";IF(OR(C214={"amazon";"tesco"});"1476";"SOURCE?")) gives Err 504
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";"SOURCE?");IF(OR(C214={"amazon";"tesco"});"1476";"SOURCE?") gives Err 509
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";"SOURCE?" works OK
Last edited by Hagar Delest on Thu Oct 28, 2021 9:37 pm, edited 1 time in total.
Reason: Tagged [Solved].
Reason: Tagged [Solved].
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
Welcome to the Forums.
I've never seen the OR function used in this manner before, but I think I understand the logic of how it should be working.
The problem you are running into is not with the OR, but with the IF.
The IF has 3 parameters. The condition that has to match, the response if it does match (aka TRUE), and the response if it does not (aka FALSE)
In the sample that works, the 1st parameter is fulfilled by the OR function. The 2nd parameter is the term "Paypal", and the 3rd parameter is the term "SOURCE?"
There is no option in Calc for a 4th parameter, which is where you are having your problem.
A rewrite (untested) could look like
I've never seen the OR function used in this manner before, but I think I understand the logic of how it should be working.
The problem you are running into is not with the OR, but with the IF.
The IF has 3 parameters. The condition that has to match, the response if it does match (aka TRUE), and the response if it does not (aka FALSE)
In the sample that works, the 1st parameter is fulfilled by the OR function. The 2nd parameter is the term "Paypal", and the 3rd parameter is the term "SOURCE?"
There is no option in Calc for a 4th parameter, which is where you are having your problem.
A rewrite (untested) could look like
Code: Select all
=if(or(c214={Boots";"pockington's bakery";"ebay"});"Paypal";if(or(c214={amazon";"tesco"});"1476";"SOURCE?");"SOURCE?")
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
Re: Nested conditionals with OR
sashcramp,
please upload your ODF type sample file here.
please upload your ODF 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.
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.
Re: Nested conditionals with OR
This manner is also new to me. What does it mean?RusselB wrote:I've never seen the OR function used in this manner before, [...]
Code: Select all
C214={"Boots";"pocklington's bakery";"ebay"}
If so, it won't not give the expected result. Cf. the screenshot.
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 7.6.6
Windows 7,10,11 64-bit
LibreOffice 3.3.0.4 – 7.6.6
Windows 7,10,11 64-bit
Re: Nested conditionals with OR
Please upload a real sample spreadsheet document 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.
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.
Re: Nested conditionals with OR
Here you go, though it is a rudimentary test.
The OP should give his/her view and provide the file you've asked for.
The OP should give his/her view and provide the file you've asked for.
- Attachments
-
- testFILE.ods
- (8.19 KiB) Downloaded 127 times
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 7.6.6
Windows 7,10,11 64-bit
LibreOffice 3.3.0.4 – 7.6.6
Windows 7,10,11 64-bit
Re: Nested conditionals with OR
A read of the offline help on array formulas might be entertaining
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Re: Nested conditionals with OR
Here is an another tip:
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.
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.
Re: Nested conditionals with OR
And a read of the online help on array formulas might be entertaining too.robleyd wrote:A read of the offline help on array formulas might be entertaining
But joking aside, I just asked a question to be on the safe side.
I remember a post on some forum (long ago) — after analysis, it turned out that the OP "misused" {}.
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 7.6.6
Windows 7,10,11 64-bit
LibreOffice 3.3.0.4 – 7.6.6
Windows 7,10,11 64-bit
Re: Nested conditionals with OR
Thanks. Here is the spreadsheet sample.Zizi64 wrote:Please upload a real sample spreadsheet document here.
My original formula was just a number of nested conditionals that returned the appropriate result in col B for col A. Using this, I must add a whole new conditional each time a new term crops up in A. I was trying the array formula hoping to type in only the new term.
- Attachments
-
- sample sheet.ods
- (12.96 KiB) Downloaded 118 times
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
Yes, I think you're right, there. Even though I thought it was working, I tested it further and it wasn't ! What I'm trying to achieve is "If the cell contains A, B or C then print "Paypal", if the cell contains X,Y or Z then print "1476" else print "SOURCE?".cwolan wrote:This manner is also new to me. What does it mean?RusselB wrote:I've never seen the OR function used in this manner before, [...]
Is this to check whether cell C214 contains a value from the set {...} ?Code: Select all
C214={"Boots";"pocklington's bakery";"ebay"}
If so, it won't not give the expected result. Cf. the screenshot.
When a term other than A B C X Y or Z crops up in the cell, I'd like to be able to add just that term to the formula, rather than type a whole nested conditional, as I was previously doing.
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
Have you considered a lookup table?
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Re: Nested conditionals with OR
Thanks. I suspect I'm also making a mistake trying to use OR and an array formula to achieve what I want.RusselB wrote:Welcome to the Forums.
I've never seen the OR function used in this manner before, but I think I understand the logic of how it should be working.
The problem you are running into is not with the OR, but with the IF.
The IF has 3 parameters. The condition that has to match, the response if it does match (aka TRUE), and the response if it does not (aka FALSE)
In the sample that works, the 1st parameter is fulfilled by the OR function. The 2nd parameter is the term "Paypal", and the 3rd parameter is the term "SOURCE?"
There is no option in Calc for a 4th parameter, which is where you are having your problem.
A rewrite (untested) could look likeCode: Select all
=if(or(c214={Boots";"pockington's bakery";"ebay"});"Paypal";if(or(c214={amazon";"tesco"});"1476";"SOURCE?");"SOURCE?")
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
Thanks for the suggestion but unfortunately I can't sort the searchtable in my particular application.robleyd wrote:Have you considered a lookup table?
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
I'm beginning to empathise with that OP I'm probably barking up the wrong tree by trying to use OR with array formulas, anyway. Thanks for the sample sheet, by the way.cwolan wrote:And a read of the online help on array formulas might be entertaining too.robleyd wrote:A read of the offline help on array formulas might be entertaining
But joking aside, I just asked a question to be on the safe side.
I remember a post on some forum (long ago) — after analysis, it turned out that the OP "misused" {}.
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
Surprisingly (to me, at least), the use of OR() with array input changes the evaluation mode into array context just fine. It is not wrong. You just need to meticulously plan the evaluation.sashcramp wrote:I'm probably barking up the wrong tree by trying to use OR with array formulas, anyway.
The error lies in formula structure. I will elaborate on RussellB's answer, which is essentially correct, baring a small bug.
Structure of the IF function is:
=IF(<expression to be evaluated for zero (FALSE) or nonzero (TRUE)> ; <expression to be returned for TRUE> ; <expression to be returned for FALSE>)
Applying the color coding to your formula:
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";"SOURCE?";IF(OR(C214={"amazon";"tesco"});"1476";"SOURCE?"))
The black part at the end constitutes the fourth parameter which RussellB mentions, and which is totally irrelevant to IF syntax and therefore unsupported, thus returning an error.
With your small data set it can be converted as per RussellB's strategy. Alas, he accidentally introduced another fourth parameter, or I may say "inherited" from your other formula suggestion. This slight rephrase should work:
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";IF(OR(C214={"amazon";"tesco"});"1476";"SOURCE?"))
The inner IF() constitutes the third parameter to the outer IF().
That said, with larger data sets and occasional changes to payment, inline arrays easily become unmanageable. Also, inline arrays can only contain constant values, no references or calculations, which is often a significant limitation. Use a lookup function instead.
You need exact matches for this, which requires the use of VLOOKUP(), HLOOKUP() or MATCH() with the "sorted" parameter set to false/0. Thus, your table does not have to be sorted.sashcramp wrote:Thanks for the suggestion but unfortunately I can't sort the searchtable in my particular application.
Re: Nested conditionals with OR
With cells instead of inline arrays:
=IF(ISNUMBER(MATCH(C214 ; $X$1:$X$99 ; 0)) ; "Paypal" ; IF(ISNUMBER(MATCH(C214 ; $Y$1:$Y$99 ; 0)) ; "1476" ; "SOURCE?"))
where $X$1:$X$99 and $Y$1:$Y$99 are arbitrary columns with the criteria replacing the inline array. MATCH can deal with columns and rows as well.
=IF(ISNUMBER(MATCH(C214 ; $X$1:$X$99 ; 0)) ; "Paypal" ; IF(ISNUMBER(MATCH(C214 ; $Y$1:$Y$99 ; 0)) ; "1476" ; "SOURCE?"))
where $X$1:$X$99 and $Y$1:$Y$99 are arbitrary columns with the criteria replacing the inline array. MATCH can deal with columns and rows as well.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Nested conditionals with OR
Many thanks! I couldn't detect the bug but I see it now. This works well but, as you say, I'm using a small dataset and I can't add a third payment type due to the limit of 3 parameters. I'll read up on the lookup function. Thanks again.keme wrote:Surprisingly (to me, at least), the use of OR() with array input changes the evaluation mode into array context just fine. It is not wrong. You just need to meticulously plan the evaluation.sashcramp wrote:I'm probably barking up the wrong tree by trying to use OR with array formulas, anyway.
The error lies in formula structure. I will elaborate on RussellB's answer, which is essentially correct, baring a small bug.
Structure of the IF function is:
=IF(<expression to be evaluated for zero (FALSE) or nonzero (TRUE)> ; <expression to be returned for TRUE> ; <expression to be returned for FALSE>)
Applying the color coding to your formula:
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";"SOURCE?";IF(OR(C214={"amazon";"tesco"});"1476";"SOURCE?"))
The black part at the end constitutes the fourth parameter which RussellB mentions, and which is totally irrelevant to IF syntax and therefore unsupported, thus returning an error.
With your small data set it can be converted as per RussellB's strategy. Alas, he accidentally introduced another fourth parameter, or I may say "inherited" from your other formula suggestion. This slight rephrase should work:
=IF(OR(C214={"Boots";"pocklington's bakery";"ebay"});"Paypal";IF(OR(C214={"amazon";"tesco"});"1476";"SOURCE?"))
The inner IF() constitutes the third parameter to the outer IF().
That said, with larger data sets and occasional changes to payment, inline arrays easily become unmanageable. Also, inline arrays can only contain constant values, no references or calculations, which is often a significant limitation. Use a lookup function instead.You need exact matches for this, which requires the use of VLOOKUP(), HLOOKUP() or MATCH() with the "sorted" parameter set to false/0. Thus, your table does not have to be sorted.sashcramp wrote:Thanks for the suggestion but unfortunately I can't sort the searchtable in my particular application.
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
That's interesting, thanks, it would save me altering the formula each time there's a new term in col C !Villeroy wrote:With cells instead of inline arrays:
=IF(ISNUMBER(MATCH(C214 ; $X$1:$X$99 ; 0)) ; "Paypal" ; IF(ISNUMBER(MATCH(C214 ; $Y$1:$Y$99 ; 0)) ; "1476" ; "SOURCE?"))
where $X$1:$X$99 and $Y$1:$Y$99 are arbitrary columns with the criteria replacing the inline array. MATCH can deal with columns and rows as well.
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
Use a Named Range, and use the name in the formula.it would save me altering the formula each time there's a new term in col C !
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.
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.
Re: Nested conditionals with OR
Thanks.Zizi64 wrote:Use a Named Range, and use the name in the formula.it would save me altering the formula each time there's a new term in col C !
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: Nested conditionals with OR
Please note the difference between "lookup functions" and "the lookup function":sashcramp wrote:...
I'll read up on the lookup function. Thanks again.
- The LOOKUP() function does require a sorted search range. This is the original spreadsheet lookup function.
- The lookup functions VLOOKUP(), HLOOKUP() and MATCH() accept the "sorted" parameter which doubles as a signal for "require exact match", and will work with unsorted search range.
Re: Nested conditionals with OR
keme wrote:Please note the difference between "lookup functions" and "the lookup function":sashcramp wrote:...
I'll read up on the lookup function. Thanks again.
- The LOOKUP() function does require a sorted search range. This is the original spreadsheet lookup function.
- The lookup functions VLOOKUP(), HLOOKUP() and MATCH() accept the "sorted" parameter which doubles as a signal for "require exact match", and will work with unsorted search range.
OK, thank you.
Apache Open Office 4.1.3
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
AOO413m1(Build:9783) - Rev. 1761381
2016-09-23 02:39:34 (Fri, 23 Sep 2016)
MAC OS Catalina 10.15.7.
Re: [Solved] Nested conditionals with OR
This does not solve the probem unless you constantly maintain the named reference. It saves some time and effort because you can maintain the name in one place while using it in many places.Zizi64 wrote:Use a Named Range, and use the name in the formula.
Instead of maintaining references, you expand all references (named and unnamed ones) by cell insertion.
Tools>Options>Calc>General> "Expand references = ON". WIth this option checked the trick works when you insert cells directly below the list.
LOOKUP is the wrong function anyway because it returns false positives.keme wrote:The LOOKUP() function does require a sorted search range. This is the original spreadsheet lookup function.
=LOOKUP(3;{0;2;4;6}) returns 2 although the searched number 3 is not in the list. Things become totally confusing with text.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice