Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
robert2012
New Contributor III

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

Re: if - elseif construction

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.

20 Replies
Sokkorn
Honored Contributor

Re: if - elseif construction

Hi robert2012,

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

Regards,

Sokkorn

sushil353
Honored Contributor II

Re: if - elseif construction

try this:

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

HTTH

Sushil

robert2012
New Contributor III

Re: if - elseif construction

Hi,

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

Error in expression:

')' expected

But I don't see where!

You?

robert2012
New Contributor III

Re: if - elseif construction

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
Contributor

Re: if - elseif construction

This should work ...

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

Message was edited by: Anand K

robert2012
New Contributor III

Re: if - elseif construction

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

Re: if - elseif construction

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

 

robert2012
New Contributor III

Re: if - elseif construction

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
Contributor

Re: if - elseif construction

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

Community Browser