10 Replies Latest reply on Jan 15, 2020 1:24 AM by Jonathan Okusanya

# Creating Calculated Field with IF statement + OR for multiple options

I am trying to create a Calculated Field with an IF statement that can take multiple options:

IF [my_letter] = 'A'

THEN 'Vowel'

IF [my_letter] = 'E'

THEN 'Vowel'

IF [my_letter] = 'I'

THEN 'Vowel'

IF [my_letter] = 'O'

THEN 'Vowel'

IF [my_letter] = 'U'

THEN 'Vowel'

ELSE 'Consonant'

Is there a way to write this in a simplified way with OR so that I don't need to repeat several times the same? Something like this:

IF [my_letter] = 'A' OR 'E' OR 'I' OR 'O' OR 'U'

THEN 'Vowel'

ELSE 'Consonant'

Thank you

• ###### 1. Re: Creating Calculated Field with IF statement + OR for multiple options

Hi dhekar,

You can write a calculated field as follows.

IF [my_letter] = 'A' OR [my_letter] = 'E' OR [my_letter] = 'I' OR [my_letter] = 'O' OR [my_letter] = 'U'

THEN 'Vowel'

ELSE 'Consonant'

END

• ###### 2. Re: Creating Calculated Field with IF statement + OR for multiple options

Is there a way to accomplish the same without having to repeat [my_letter] for every OR clause?

• ###### 3. Re: Creating Calculated Field with IF statement + OR for multiple options

Hi,

Try this,

IIF(REGEXP_MATCH([My Letter],'A|E|I|O|U'),'Vowel','Consonant')

Let us know if this help.

Mahfooj

1 of 1 people found this helpful
• ###### 4. Re: Creating Calculated Field with IF statement + OR for multiple options

Kya Baat Hai

• ###### 5. Re: Creating Calculated Field with IF statement + OR for multiple options

Aap ki kripa ha guru ji

• ###### 7. Re: Creating Calculated Field with IF statement + OR for multiple options

Thank you!

• ###### 8. Re: Creating Calculated Field with IF statement + OR for multiple options

dhekar If you do not want the repetition of the column header, you can simply use a regular expression IIF(REGEXP_MATCH([My Letter],'A|E|I|O|U'),'Vowel','Consonant')

1 of 1 people found this helpful
• ###### 9. Re: Creating Calculated Field with IF statement + OR for multiple options

Thanks Jonathan, I think this would indeed solve the example I posted.

However, I should have pointed out in the OP that I changed my examples for the sake of simplicity. My bad and my apologies.

Instead of letters, what I actually have are subcategories of data that need to be classified based on their name. So something like:

IF [subcategory] = 'tables' OR 'chairs' OR 'drawers' OR 'beds'

THEN 'Furniture'

ELSE 'Not Furniture'

1 of 1 people found this helpful
• ###### 10. Re: Creating Calculated Field with IF statement + OR for multiple options

Kindly mark as helpful if I helped,Thanks.