Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

IF Statement

Highlighted
6 - Meteoroid

I am trying to use following IF statement but not getting results. Wha's wrong with it?

IF [OperatingSystem]="W2K12 R2 STD" OR "W2K8 EP”

THEN [OperatingSystem]="Windows"

ELSE [OperatingSystem]="Other"

ENDIF

Highlighted
Alteryx
Alteryx

Hi @tmahmo15,

 

try this:

 

IF [OperatingSystem]="W2K12 R2 STD" OR [OperatingSystem]="W2K8 EP"

THEN "Windows"

ELSE "Other"

ENDIF

 

Also, if you are using this in a Formula tool, remember to select the field that you want to modify (OperatingSystem), see below:

 

image.png

Hope this helps!

Giuseppe

Highlighted
6 - Meteoroid

 

 

Now I am getting error - An operator must be between operands

 

tmahmo15_0-1582120104176.png

 

Highlighted
6 - Meteoroid
 
 

Are your closing parentheses correct? for the second  Operating System statement? cant tell if its just the image!

Highlighted
6 - Meteoroid

This is Snip from the Alteryx. Even if I simplify the statement as below, it is still showing as Malformed IF statement:

tmahmo15_0-1582121060464.png

 

Highlighted
6 - Meteoroid

Nothing wrong with the Statement, try replacing the " Parentheses around 'Other' too and see if that works if you haven't already. 

 

Highlighted
Alteryx
Alteryx

Hi @tmahmo15,

 

In your case, you have 2 options:

 

IF [OperatingSystem]="W2K12 R2 STD" OR [OperatingSystem]="W2K8 EP"

 

OR

 

IF [OperatingSystem] IN ("W2K12 R2 STD","W2K8 EP")
 

 

In your original expression:

 

IF [OperatingSystem]="W2K12 R2 STD" OR "W2K8 EP"

 

"W2K8 EP" is going to be interpreted as a logical expression. Its value is FALSE. As a result, only the following will be considered in your formula:

 

IF [OperatingSystem]="W2K12 R2 STD"

 

Best,

 

Paul Noirel 

Sr Customer Support Engineer, Alteryx

Highlighted
Alteryx
Alteryx

Hi @tmahmo15,

 

Look at the quote signes, i.e. the " characters. Not sure what settings you have on your keyboard, but when I copied and pasted your code into Alteryx, I had to replace the quotes. You can use single quotes to be on the safer side, as long as you are consistent (i.e. IF [OperatingSystem] = 'W2K12'... rather than "W2K12"...)

 

In your snippet below, look at the quote signes, they are 2 different characters.

image.png

 

Giuseppe

Highlighted
6 - Meteoroid

I changed my IF statement a little bit and included your suggested changes too. But the outcome is numeric values (0, -1) instead of (Windows, Linux, etc.) as you can see. 

 

tmahmo15_0-1582143714656.pngtmahmo15_1-1582143763464.png

 

Highlighted
Alteryx
Alteryx

Hi,

 

You don't need the "[OS From SPLUNK] = " text on your Then and Else steps.  The reason for this is because Alteryx formulas always write out to the "output column", so they've basically got an implied "[OS From SPLUNK] =" already.  You're getting 1's and 0's because it is currently outputting the result of a boolean test of if [OS From Splunk] is equal to the text that follows (Windows, Linux, Others).

 

Hope this helps!

Labels