Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

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

Switch Function

RanjanKT
8 - Asteroid

HI All,

 

Sorry i am quite new to the Alteryx.

 

Can some one help me to use the Switch function for the below formula instead of IF.

 

if [Stage]="Closed" then "Closed" elseif [AnticipatedWinDate]<"2019-06-28" then "Pastdue" elseif [AnticipatedWinDate]<=DateTimeAdd("2019-06-28",+30,"days") then "0-30" elseif [AnticipatedWinDate]<=DateTimeAdd("2019-06-28",+60,"days") then "31-60" elseif [AnticipatedWinDate]<=DateTimeAdd("2019-06-28",+90,"days") then "61-90" else ">90"
Endif

 

Regards,

Ranjan

4 REPLIES 4
danilang
19 - Altair
19 - Altair

Hi @RanjanKT 

 

The Alteryx switch function has one single comparison that's done at the beginning of the process

Switch(Value,Default,Case1,Result1,...,CaseN,ResultN)

as in

Switch([Class], Null(), "Gold",1,"Silver",2,"Bronze", 3,"Tin", 4, "Aluminum",5)

 

Your IF statement contains multiple different comparisons using more than one field.  Your best option here is to leave it in the 

If Then

ElseIF

Else

Endif

structure that you already have

 

Dan

DanielCh
7 - Meteor

Hi,

I have also quite big function using multiple "or" operators. I would like to use "SWITCH" function as I heard it is easier to edit ect.

Basically I have two reports, first one (A) is creating on Value Date and second one (B) is creating one week before (VD-7). They have two columns "LOCAL ID" and "COMMENTS" and report A may include repeated rows but also new rows. I am identifying repeated rows by "multiple join" tool, searching by LOCAL ID and leaving LOCAL ID from report A and COMMENTS from B. If new, some fields in COMMENTS may be "null" (I am switching to "Empty" by appropriate tool). 

Now I would like to automatically populate comments basing on "LOCAL ID", I am using below SWITCH formula (Formula tool, output column "COMMENTS") but in output, empty fields in COLUMN were populated only by "not signed yet" although they have LOCAL ID like "a", "e" or "g" (formatted as "double). 

 

 

IF (IsEmpty([Comments])) THEN
(Switch([LOCAL ID],'not signed yet'
,[LOCAL ID]=a,'X'
,[LOCAL ID]=b,'X'
,[LOCAL ID]=e,'Z'
,[LOCAL ID]=f,'Z'
,[LOCAL ID]=g,'open'
,[LOCAL ID]=h,'open'))
ELSE [Comments]
ENDIF

 

 Appreciate if any ideas on above will arrive.

 

Thanks,

 

Daniel

Steve_B_
5 - Atom

I could be wrong, but I think that this is what you would need.

 

 
IF (IsEmpty([Comments])) THEN
(Switch([LOCAL ID],'not signed yet'
,a,'X'
,b,'X'
,e,'Z'
,f,'Z'
,g,'open'
,h,'open'))
ELSE [Comments]
ENDIF
Kshitijs
5 - Atom

How to use switch function with nested IF statements in alteryx?

 Kindly answer please!

 

Labels
Top Solution Authors