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

Nested if statement

saltyplanet
7 - Meteor

I have these two if statements here. I know it is wrong because the workflow would not run.. But I can't figure out where I got it wrong. Any help will be appreciated!!

 

if !isnull([Route_ID])
   then if [Route_ID] in (880939, 880934, 548800, 548799, 548798, 548797, 548796)
            then if [Sum_ord_miles] > 2200
                 then ([Sum_ord_miles]-2200)*.88 + (2200*1.55)
                 else [Sum_ord_miles]*1.55
                 endif
        elseif [Route_ID] not in (880939, 880934, 548800, 548799, 548798, 548797, 548796)
            then if [Sum_ord_miles] > 2200
                 then ([Sum_ord_miles]-2200)*.99 + (2200*1.77)
                 else [Sum_ord_miles]*1.77
             endif
else 0
end if






if !isnull([Route_ID])  
      then if [Route_ID] in (880939, 880934, 548800, 548799, 548798, 548797, 548796)
               then if [weekly_mileage_charge] < (2200*1.55)
                    then (2200*1.55)-[weekly_mileage_charge]
                    else 0
                    endif
          elseif [Route_ID] not in (880939, 880934, 548800, 548799, 548798, 548797, 548796)
                then if [weekly_mileage_charge] < (2200*1.77)
                     then (2200*1.77)-[weekly_mileage_charge]
                     else 0
                     endif

else 0
endif

 

 

8 REPLIES 8
Kenda
16 - Nebula
16 - Nebula

What is the error that you're getting @saltyplanet ?

saltyplanet
7 - Meteor

this is the error I got

 

saltyplanet_0-1652988101574.png

 

Kenda
16 - Nebula
16 - Nebula

@saltyplanet Are you trying to put both of these separate statements in one expression?

DataNath
17 - Castor
17 - Castor

Not sure if it was maybe just an error when pasting over to here, but if not, you have a space in your final 'endif' for the first one. If it's still erroring let us know and will look over it in more detail.

 

DataNath_0-1652988711764.png

 

saltyplanet
7 - Meteor

sorry I didn't make it clear. But I was trying to just put one if statement into just one expression. 

 

so these are in two different expressions.

saltyplanet
7 - Meteor

 I removed the space in between and pasted it into the formula. I noticed the color is not populating... does it mean the !IsNull is already wrong? Like the [Route_ID] cannot be regconnized 

 

 

saltyplanet_0-1652989234009.png

 

Kenda
16 - Nebula
16 - Nebula

@saltyplanet 

 

In your first nested if, you're checking if Route_ID is in a certain set of values. First ensure that this field is numeric since you aren't using quotes here. Then, when you use the elseif expression

elseif [Route_ID] not in (880939, 880934, 548800, 548799, 548798, 548797, 548796)

you're checking if the value is not in that list. This isn't necessary because if the value isn't in that list, it will just fall into the "else" category without needing the full "elseif" expression. 

 

Hope that helps point you in the right direction! 

 

DataNath
17 - Castor
17 - Castor

How do you get on with the following?

 

if !isnull([Route ID]) then
if [Route ID] in (880939, 880934, 548800, 548799, 548798, 548797, 548796)
            then if [Sum_ord_miles] > 2200
                 then ([Sum_ord_miles]-2200)*.88 + (2200*1.55)
                 else [Sum_ord_miles]*1.55
                 endif

        elseif [Sum_ord_miles] > 2200
                 then ([Sum_ord_miles]-2200)*.99 + (2200*1.77)
                 else [Sum_ord_miles]*1.77
             endif
else 0
endif

 

 

Labels
Top Solution Authors