Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
marco_puccetti
Partner - Creator
Partner - Creator

Expression for column

I need to add a more complex script for the computation of a delta percentage for two year in a pivot table.

The script should contains the following lines of codes but the syntax checker doesn't allow me to insert the code.

How can i do?

This is the code:

Column(1): Current year field

Column(2): Previous year field

if(Column(1) > Column(2)) then

    (Column(1)-Column(2)) / Column(1);

end if

if(Column(1) <= Column(2)) then

    ((Column(2)-Column(1)) / Column(2)) * (-1);

end if

Thanks

1 Solution

Accepted Solutions
Not applicable

Hi,

IF

(

Column(1) > Column(2),

(Column(1)-Column(2)) / Column(1),

(Column(2)-Column(1)) / Column(2) * (-1)

)

Xavier.

View solution in original post

4 Replies
datanibbler
Champion
Champion

Hi Marco,

IF_THEN is a conditional function in QlikView for entire statements or blocks of code - you cannot use it in an expression.

Try like this:

IF(Column(1) > Column(2)),

    (Column(1)-Column(2)) / Column(1),

   if(Column(1) <= Column(2)),

    ((Column(2)-Column(1)) / Column(2)) * (-1)))

I'm not quite sure about the number of closing brackets at the end, but the expression_editor will tell you.

HTH

Not applicable

Hi,

IF

(

Column(1) > Column(2),

(Column(1)-Column(2)) / Column(1),

(Column(2)-Column(1)) / Column(2) * (-1)

)

Xavier.

marco_puccetti
Partner - Creator
Partner - Creator
Author

Ok with this sintax it works, but if i need a more complex expression that has to be written on more lines how can i do?

Thanks

Marco

Not applicable

The syntax is :

If (condition, expression if true, expression if false)

=> you can imbricate more IF statements into the "expression if false".

Example:

If ( a=1, 'a',If (a=2, 'b',If (a=3, 'c',If (a=4, 'd', 'z'))))

or

If ( a=1, 'a',

If (a=2, 'b',

If (a=3, 'c',

If (a=4, 'd', 'z'))))

is equivalent to :

if a=1 then

     'a'

elseif a=2 then

     'b'

elseif a=3 then

     'c'

elseif a=4 then

     'd'

else

     'z'

end if


Xavier.