Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Using Switch to for an interval of numbers?

underkj
6 - Meteoroid

I know that I can do this relatively easy with an if statement. But I am guessing that I can also do it with a Switch to make it relatively easier. I am just having trouble with the syntax I think.

 

Number 
3
6
9

 

Switch([Number], " Greater than 9 ", < 3, " < 3", <= 6, " <= 6", <= 9, "<=9")

 

Thanks in advance. If I have to type the field [Number] before each operator then what's the point of switch?

 

2 REPLIES 2
Qiu
20 - Arcturus
20 - Arcturus

I am afaid that we may not.

According the help, we can not really use any formula or statement as criteria. 

The Else if should be considered.

 

Switch.png

apathetichell
18 - Pollux

You can do what you are trying to do with a switch - but you need to  think about "how do I make my comparison versus a finite value?" In your case:

Number 
3
6
9

 

Switch([Number], " Greater than 9 ", < 3, " < 3", <= 6, " <= 6", <= 9, "<=9")

 

Can be re-written as:

switch(floor(([Number ]-1)/3)+1,">9",1,"<=3",2,"<=6",3,"<=9")

 

This is the floor division of your number -1 by 3 then with 1 added (so your base case is 1.) Subtracting 1 from your number transforms the number which is divisible by 3 from being the smallest entry in the new set to the largest entry in the previous set.

 

 

Labels