Select to view content in your preferred language

If "and" statement not working as expected

538
5
Jump to solution
01-30-2025 03:11 PM
WilderNiss1
Occasional Contributor

I have a simple if statement (it's actually part of a much larger if statement, but this is the part giving me issues) that I can't figure out and I'm hoping to get some help on. 

 

The issue I'm having is that the result always returns "hh", even when I select "vehicle" and "unk" or "no". In that situation I am hoping for a result of "vv", since the other selections shouldn't be possible when "vehicle" is not selected for the field ${human_loss_category_new_nest}. Any thoughts? I'm sure it's probably just syntax but I can't figure it out. Thank you!!

if((${failure_category_new_nest} = "human" and (${human_loss_category_new_nest} = "eggs taken" or "eggs trampled" or "eggs destroyed") and ${deliberate_new_nest} = "yes"), "vz",
if((${failure_category_new_nest} = "human" and (${human_loss_category_new_nest} = "eggs taken" or "eggs trampled" or "eggs destroyed") and (${deliberate_new_nest} = "unk" or "no")), "hh",

if((${failure_category_new_nest} = "human" and ${human_loss_category_new_nest} = "vehicle" and (${deliberate_new_nest} = "unk" or ${deliberate_new_nest} ="no")), "vv")))

0 Kudos
1 Solution

Accepted Solutions
AdamMesser1
Regular Contributor

@WilderNiss1 Your OR  statements are mixed. In your first lines you use (${deliberate_new_nest} = "unk" or "no")  which is a list of values separated by or . The last lines use (${deliberate_new_nest} = "unk" or ${deliberate_new_nest} ="no"). I think S123 may require the later approach where each value is preceded by the @{field}= .

View solution in original post

5 Replies
WilderNiss1
Occasional Contributor

I should clarify, the result always results in "hh" if I select "no" or "unk". If there is a yes, it returns "vz" which is good

0 Kudos
AdamMesser1
Regular Contributor

@WilderNiss1 Your OR  statements are mixed. In your first lines you use (${deliberate_new_nest} = "unk" or "no")  which is a list of values separated by or . The last lines use (${deliberate_new_nest} = "unk" or ${deliberate_new_nest} ="no"). I think S123 may require the later approach where each value is preceded by the @{field}= .

WilderNiss1
Occasional Contributor

@AdamMesser1 - Is that true for the AND statements too, or just the OR statements? Right now it appears that the AND statement works, but I could be missing something. 

0 Kudos
AdamMesser1
Regular Contributor

@WilderNiss1  Yes, that is my understanding. I don't have time to look into it/test right now but my approach to nested functions that are being difficult is stepwise testing. If you create a series of test S123 fields you can verify each set of choices at the most nested level first. Once that works, then copy it up to the next level in a new field, and repeat until the top or most outermost level is reached. Usually, these types of syntax errors have a simple solution, but looking at them all makes them hard to decipher.

WilderNiss1
Occasional Contributor

Thanks @AdamMesser1 - adding the @{field}= everywhere in the syntax that had an "or" did the trick!