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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
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.

20 Replies
Anonymous
Not applicable
Author

There is still a problem with "

:

If takes 2-3 parameters"

and if I put $ away QlikView doens't find the field as it is a varible ?!

Hope you know why and you can help me

Not applicable
Author

Hi Rob!

There are 2 kinds of "IF" keyword.

The 1st is when you use it in Data Loading, use this syntax:

IF (condition) THEN

{statement_if_true}

ELSE

{statement_if_false}

END IF

The 2nd if is available in the Expression dialog with syntax:

=IF(condition, statement_if_true, statement_if_false)

It think what you're looking for is in the expression, which is 2nd if.

Hope that helps

A

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.

Anonymous
Not applicable
Author

I use like you wrote:

Projekte_Monat:

LOAD MAID_Z,

  left (MAID_Z, 14) as MAID_gesamt_Z,

  If ($(reisezeit) = 1,

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

      sum(Stunden)

      ) as Stunden_Projekt

Resident ControllerExport_tmp1

Group by MAID_Z;

But there is always:

Error in expression: If takes 2-3 parameters

Anonymous
Not applicable
Author

Hi Adrian,

thank you for your help: I'm looking for the Data Loading:

I changed to:

Projekte_Monat:

LOAD MAID_Z,

  left (MAID_Z, 14) as MAID_gesamt_Z,

If $(reisezeit) = 1 then

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

      else

      sum(Stunden) as Stunden_Projekt;

        ENDIF

   

Resident ControllerExport_tmp1

Group by MAID_Z;

But there is still a mistake with my syntax, I can't solve

er_mohit
Master II
Master II

Write this within load statement where your field Stunden exists in table

load

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

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

kumarnatarajan
Partner - Specialist
Partner - Specialist

Hi,

try this one.

Projekte_Monat:

LOAD

  MAID_Z,
left (MAID_Z, 14) as MAID_gesamt_Z,
If($(reisezeit)=1,if(Reisezeit='Nein', Sum(Stunden)),sum(Stunden)) as Stunden_Project  
Resident ControllerExport_tmp1
Group by MAID_Z;

where you are decler this variable. send your full script. reisezeit variable value standard or random.

Not applicable
Author

It's strange because i use the exact script you wrote in a test application and it works. (I have created an inline table with the 3 fields Reisezeit, Stunden and MAID_Z).

These 3 fields exist in the table ControllerExport_tmp1 ?

Anonymous
Not applicable
Author

Hi I changed to:

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

if($(reisezeit) = 0,sum(Stunden)) as Stunden_Projekt

This works, but the results are wrong!

If I compare to:

sum (Stunden) as Stunden_Projekt

there are different results => Do you have an explanation/idee?

Thank you!

Anonymous
Not applicable
Author

I just wrote

set reisezeit = 0; //at the beginning of the skript

But theere is invalid expression!

Is there a problem with the variable?