Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
Hi,
IF
(
Column(1) > Column(2),
(Column(1)-Column(2)) / Column(1),
(Column(2)-Column(1)) / Column(2) * (-1)
)
Xavier.
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
Hi,
IF
(
Column(1) > Column(2),
(Column(1)-Column(2)) / Column(1),
(Column(2)-Column(1)) / Column(2) * (-1)
)
Xavier.
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
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.