Skip to main content
Announcements
Qlik Community Office Hours, March 20th. Former Talend Community users, ask your questions live. SIGN UP
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If..then..elseif..endif

I'm trying to get this compound if to work but having problems with the syntax.  any ideas?  Thanks.

If ([Bill To Address] = 3670 or 5970,
if (PDorSP = 'PD', 'MY',
if (PDorSP = 'SP',
if (SDSRP2 = 'PEA' or 'SOY', 'MY',
if (SDSRP2 <> 'PEA' and 'SOY', 'LI'))))),
//*
else if (PDorSP = 'PD', PTSM,
If(PDorSP = 'SP', STSM,
If(PDorSP = 'FB', 'PB',
If(
[Line Type] = 'MP' or [Line Type] = 'FP',PTSM,
If(
[Line Type] = 'MS' or [Line Type] = 'FS',STSM,
if (
[Line Type] = 'M' or [Line Type] = 'F' or [Line Type] = 'Z' or [Line Type] = 'Y',
if (SDSRP1 = 'PD', PTSM,
if (SDSRP1 = 'SP', STSM,
if (SDSRP1 = 'FB' or SDSRP1 = 'PKG' or SDSRP1 = 'CMF' or SDSRP1 = 'RAW' or SDSRP1 = 'OTH', 'PB',)))))))))
end if as
[Territory Manager],


5 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Change all conditions like

[Bill To Address] = 3670 or 5970


that don't work in QlikView, into


([Bill To Address] = 3670) or ([Bill To Address] = 5970)


Use lots of indentation and parentheses to separate the different clauses in your statement.


Best, Peter

Not applicable
Author

Hi Frank,

the If syntax within the QV load script isn't in that format, needs to be like the below

IF(Evaluation,[True Condition],[False Condition])

You can't you elseif like that when creating a field.

Also using the Or/And like that will not give the required result, you need to specify the OR/AND separately

i.e

If([Bill to Address]=3670 OR [Bill to Address]=5970, [True], [False})

hope that helps

Joe

Not applicable
Author

Thank Peter & Joe,

I made the correction you suggested, however I'm still receiving an error when the script runs.  I'm not sure that the else is working properly.  As you will notice all the "if" after the else are not in blue the way they should be.

If ([Bill To Address] = 3670 or [Bill To Address] = 5970,
if (PDorSP = 'PD', 'MY',
if (PDorSP = 'SP',
if (SDSRP2 = 'PEA' or 'SOY', 'MY',
if (SDSRP2 <> 'PEA' or SDSRP2 <> 'SOY', 'LI'))))),
//*
else if (PDorSP = 'PD', PTSM,
If(PDorSP = 'SP', STSM,
If(PDorSP = 'FB', 'PB',
If(
[Line Type] = 'MP' or [Line Type] = 'FP',PTSM,
If(
[Line Type] = 'MS' or [Line Type] = 'FS',STSM,
if (
[Line Type] = 'M' or [Line Type] = 'F' or [Line Type] = 'Z' or [Line Type] = 'Y',
if (SDSRP1 = 'PD', PTSM,
if (SDSRP1 = 'SP', STSM,
if (SDSRP1 = 'FB' or SDSRP1 = 'PKG' or SDSRP1 = 'CMF' or SDSRP1 = 'RAW' or SDSRP1 = 'OTH', 'PB',)))))))))
end if as
[Territory Manager],


Not applicable
Author

Hi Frank,

like I said, you can't use elseif like that for an if statement when creating fields, you'll need to rework the elseif to get that to work

Joe

Peter_Cammaert
Partner - Champion III
Partner - Champion III

The IF you use in column assignments is a function with either two or three parameters. It doesn't have an ELSE clause because the else clause is the third parameter.

IF THEN ELSE statements are control statements and allowed only outside of LOAD statements.