Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

If Then statement parse error (malformed statement)

aberthiaume
7 - Meteor

I wrote an if/then statement with many conditions.  it is telling me I have a parse error at the last character of the code but it does not turn black.  I have tried to remove the enter and then I get a squiggly line under "endif" shwoing that is an error.  I put the return back in and it gives me the parse error again.  I am not sure what I could be doing wrong, but I feel it is something simple.  Would someone take a look and see if you can identify the cause?  

 

aberthiaume_0-1656690084164.png

 

 

Here is the code... 

 

If [Measure Code] = "CAUTI_RATE_ICU_P" or if [Measure Code] = "CLABSI_RATE_ICU_P" or if [Measure Code] = "MRSA_RATE" or if [Measure Code] = "ADE_ANTICOAG" or if [Measure Code] = "PU_STAGE3" then ([Performance Numerator]/[Performance Denominator]) * 1000 else if [Measure Code] = "CDIFF_RATE" then ([Performance Numerator]/[Performance Denominator]) *10000 else if [Measure Code] = "SSI_COLO_RATE" or if [Measure Code] = "SSI_HYST_RATE" or if [Measure Code] = "SSI_KPRO_RATE" or if [Measure Code] = "COVID_VAC_COMP" or if [Measure Code] = "COVID_ED_NON_VENT" or if [Measure Code] = "COVID_ED_VENT" or if [Measure Code] = "COVID_HOSP_ONSET" or if [Measure Code] = "ADE_HYPOGLYCEMIA" or if [measure code] = "ADE_OPIOID_RATE" or if [Measure Code] = "READM_30D_HW" or if [Measure Code] = "SEPSIS_MORT" or if [Measure Code] = "SEPSIS_SHOCK" then ([Performance Numerator]/[Performance Denominator]) * 100 else ([Performance Numerator]/[Performance Denominator]) endif

5 REPLIES 5
apathetichell
18 - Pollux

Does this work:

 

If [Measure Code] IN ("CAUTI_RATE_ICU_P", "CLABSI_RATE_ICU_P","MRSA_RATE","ADE_ANTICOAG","PU_STAGE3") then ([Performance Numerator]/[Performance Denominator]) * 1000 elseif [Measure Code] = "CDIFF_RATE" then ([Performance Numerator]/[Performance Denominator]) *10000 elseif [Measure Code] IN("SSI_COLO_RATE", "SSI_HYST_RATE","SSI_KPRO_RATE","COVID_VAC_COMP" ,"COVID_ED_NON_VENT","COVID_ED_VENT","COVID_HOSP_ONSET", "ADE_HYPOGLYCEMIA","ADE_OPIOID_RATE","READM_30D_HW", "SEPSIS_MORT","SEPSIS_SHOCK") then ([Performance Numerator]/[Performance Denominator]) * 100 else ([Performance Numerator]/[Performance Denominator]) endif

 

I'm surpised alteryx didnt' flag "or if" from the get-go. Or implies a second IF statement so that's wrong. It's just OR.

kathleenmonks
Alteryx
Alteryx

Hi @aberthiaume 

 

"else if" should be "elseif" and you do not need the "if" after each "or"

 

This should work:

 

If [Measure Code] = "CAUTI_RATE_ICU_P" or [Measure Code] = "CLABSI_RATE_ICU_P" or [Measure Code] = "MRSA_RATE" or [Measure Code] = "ADE_ANTICOAG" or [Measure Code] = "PU_STAGE3"
then ([Performance Numerator]/[Performance Denominator]) * 1000
elseif [Measure Code] = "CDIFF_RATE"
then ([Performance Numerator]/[Performance Denominator]) *10000
elseif [Measure Code] = "SSI_COLO_RATE" or [Measure Code] = "SSI_HYST_RATE" or [Measure Code] = "SSI_KPRO_RATE" or [Measure Code] = "COVID_VAC_COMP" or [Measure Code] = "COVID_ED_NON_VENT" or [Measure Code] = "COVID_ED_VENT" or [Measure Code] = "COVID_HOSP_ONSET" or [Measure Code] = "ADE_HYPOGLYCEMIA" or [Measure code] = "ADE_OPIOID_RATE" or [Measure Code] = "READM_30D_HW" or [Measure Code] = "SEPSIS_MORT" or [Measure Code] = "SEPSIS_SHOCK"
then ([Performance Numerator]/[Performance Denominator]) * 100
else ([Performance Numerator]/[Performance Denominator])
endif

DataNath
17 - Castor

@aberthiaume you don’t need to keep restarting your ifs so every time you have ‘or if’ you just need ‘or’. I can also see that you use ‘else if’ which should be one word ‘elseif’.

 

Because you’re restarting the if statement (or nesting), Alteryx will be looking for an else/then/endif for every single instance of this.

DataNath
17 - Castor

Also (sorry, on mobile so can’t edit)… instead of typing out loads of ‘or’ statements to check the same variable, you can just use IN, so:

 

if [Measure Code] IN (‘A’,’B’,’C’) then…

 

Where ABC (and more if needed) are the values you’re checking for such as CAUTI_RATE_ICU.

camie
6 - Meteoroid

can you try this

If [Measure Code] IN ("CAUTI_RATE_ICU_P","CLABSI_RATE_ICU_P","MRSA_RATE",
"ADE_ANTICOAG","PU_STAGE3") then
([Performance Numerator]/[Performance Denominator]) * 1000
elseif
[Measure Code] = "CDIFF_RATE" then
([Performance Numerator]/[Performance Denominator]) * 10000
elseif
[Measure Code] IN ("SSI_COLO_RATE","SSI_HYST_RATE","SSI_KPRO_RATE","COVID_VAC_COMP","COVID_ED_NON_VENT","COVID_ED_VENT","COVID_HOSP_ONSET","ADE_HYPOGLYCEMIA",
"ADE_OPIOID_RATE","READM_30D_HW","SEPSIS_MORT","SEPSIS_SHOCK") then ([Performance Numerator]/[Performance Denominator]) * 100
else
([Performance Numerator]/[Performance Denominator])
endif

Labels