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.
SOLVED

Categorizing Text Descriptions using If Then Else

cwilcoxmtn
7 - Meteor

We are creating a hierarchical structure for our products.  They currently have details in the description (text), which we are moving to Categories using Integers.  I have a monster If then statement.  I believe there is probably a better way to do it.

 

For this small section: (for example)

01Air Master
02Air Duct
03Plant Master Xtreme
04Plant Master Xtreme 300 AR
05Plant Master Xtreme 300 Lock-On Braid
06Plant Master Xtreme 325 Braid
07Plant Master Xtreme 501AR
08Plant Master Plus
09Plant Master Plus 300 Lock-On
10Plant Master
11Plant Master 250
12Plant Master 300
13Plant Master 300 NC

 

I've created this code in a Formula tool:

 

If Contains([PN & Desc],"Air M") then "01" elseif
Contains([PN & Desc],"Air D") then "02" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc],"Xtreme") and Contains([PN & Desc],"AR") and Contains([PN & Desc],"300")) then "04" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc],"Xtreme") and Contains([PN & Desc],"Lock") and Contains([PN & Desc],"300")) then "05" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc],"Xtreme") and Contains([PN & Desc],"Braid")) then "06" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc],"Xtreme") and Contains([PN & Desc],"501")) then "07" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc],"Xtreme")) then "03" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc], "Plus") and Contains([PN & Desc],"Lock")) then "09" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc], "Plus")) then "08" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc], "250")) then "11" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc], "300") and contains([PN & Desc],"NC")) then "13" elseif
(Contains([PN & Desc],"Plant") AND Contains([PN & Desc], "300")) then "12" elseif
Contains([PN & Desc],"Plant") then "10"
else "99" endif

 

It would be useful if I there is nested if available:

 

If "Plant" (If "Extreme" (If "300" (If "AR" ) then "04" (If "Lock") then "05". . etc.. Realize my syntax is bad, just wanted to give an idea of what I'm thinking.

 

One more caveat.  Sometimes the desc doesn't contain "Master" but may be "Mstr" or "Plant M". . etc.

 

Thank you for any help!!

2 REPLIES 2
jasperlch
12 - Quasar

Hi, the workflow attached might not make your workflow simpler. But I think it makes it more dynamic and easier to maintain. Say, when you need to add/remove/update the Categories, you do not need to update your formula but instead, you only need to update the Category mapping table.

 

Capture1.PNG

cwilcoxmtn
7 - Meteor

This is much better!  Very elegant.  Thank you!!!  

Labels