Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

if - elseif construction

Hi all,

I would like to use the following statement in my script, but it doesn't work:

"reisezeit" is a variable which can be 0 or 1.

if reisezeit = 1 then

                              sum(if(Reisezeit='Nein', Stunden) )as Stunden_Projekt;

                              elseif

                              reisezeit = 0

                              sum(Stunden) as Stunden_Projekt;

                              ELSE

                              sum(Stunden) as Stunden_Projekt;

                    end if

Does someone has an idea why?

Thank you for your help.

1 Solution

Accepted Solutions
Not applicable
Author

If you use other fields in your load statement, you must have a Group By Clause in your script.

LOAD

dimension1,

If ($(reisezeit) = 1,

   
sum(if(Reisezeit='Nein', Stunden)),

   
sum(Stunden)

    )
as Stunden_Projekt

RESIDENT Data

GROUP BY dimension1 ; 

I used dmension1 as example.

View solution in original post

20 Replies
Sokkorn
Master
Master

Hi robert2012,

Can you change if reisezeit to if $(reisezeit) then try again.

Regards,

Sokkorn

sushil353
Master II
Master II

try this:

if($(Reisezeit) = 1,sum(if($(Reisezeit)='Nein', Stunden,if($(Reisezeit) = 0,sum(Stunden))))) as Stunden_Projekt

HTTH

Sushil

Anonymous
Not applicable
Author

Hi,

thx, but there is still a mistake as QlikView says:

Error in expression:

')' expected

But I don't see where!

You?

Anonymous
Not applicable
Author

Hi Sokkorn,

thank you very much.

I changed the first and both, but it still doens't work.

It says: Syntax Fehler

You know why?

anandathome
Creator
Creator

This should work ...

if(reisezeit=1,sum(if(Reisezeit='Nein',Stunden)),sum(Stunden))  as Stunden_Projekt;

Message was edited by: Anand K

Anonymous
Not applicable
Author

Hi,

thank u for your help:

I added $ for the variables:

if($(reisezeit) = 1,sum(if($(reisezeit)='Nein',Stunden)),sum(Stunden))  as Stunden_Projekt

Now QlikView says:

If takes 2-3 parameters

Not applicable
Author

Try this :

if ($(reisezeit) = 1,

   
sum(if(Reisezeit='Nein', Stunden)),

   
if($(reisezeit)=0,

      
sum(Stunden),

      
sum(Stunden)

       )

     )
as Stunden_Projekt ;

If your variable takes only values 1 or 0, you can also write this :

if ($(reisezeit) = 1,

   
sum(if(Reisezeit='Nein', Stunden)),

   
sum(Stunden)

    )
as Stunden_Projekt

 

Anonymous
Not applicable
Author

Hi Marie-Sophie Blond,

Thank you!

But there is "Error in expression: If takes 2-3 parameters"

for both ideas.

What can I do?

anandathome
Creator
Creator

Remove the '$' sign and it should work for you