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 with a variable

Hi all,

I have a problem with the following skript:

if ($(Menu) = 1,

sum (Stunden where Reiszeit = 'Nein'),         // only Stunden with "Nein"

sum (Stunden)) as Stunden_Projekt             // all Stunden

I would like to controll the two different sums per variable.

The problem is that I don't get the right skript for this.

Thank you for helping

1 Solution

Accepted Solutions

Re: if with a variable

HI

PFA

Regards,

R.Mayil Vahanan

14 Replies
Not applicable

Re: if with a variable

try this

if ($(Menu) = 1 or Reiszeit = 'Nein',Stunden,Stunden) as Stunden_Projekt 

robert2012
New Contributor III

Re: if with a variable

Thank you for your answer!

And what about the sum?

er_mohit
Honored Contributor II

Re: if with a variable

sum(if ($(Menu) = 1 or Reiszeit = 'Nein',Stunden,Stunden) ) as Stunden_Projekt        

hope it helps

Not applicable

Re: if with a variable

sum(if($(Menu) <> 1 or Reiszeit = 'Nein', Stunden))

robert2012
New Contributor III

Re: if with a variable

Hi,

there is still a mistake:

Error in expression:

')' expected

Testfile:

LOAD MAID_Z,

left (MAID_Z, 14) as MAID_gesamt_Z,

sum(if( <> 1 or Reiszeit = 'Nein', Stunden))  as Stunden_Projekt

Resident table1

Group by MAID_Z

... and I would like to sum a) Stunden where Reisezeit = "Nein" and menu = 1

                                        b) (else) sum all Stunden also where Reisezeit = "Ja" and "Nein"

=> my idea is to switch the filter of Reizeit "JA" / "Nein" with the variable menu

Hope it helps...

Thank you all for your assistance.

Not applicable

Re: if with a variable

You forgot to set $(Menu) variable - it's blank in your example, if it possible(a blank) then try this:

sum(if('$(Menu)' <> '1' or Reiszeit = 'Nein', Stunden))


or just set $(Menu) to needed value.

robert2012
New Contributor III

Re: if with a variable

Sorry, I still don't get it.

Why do you take "or"? The aim is to have a variable that switches the sum-function between all "Stunden" and the "Stunden" which have also Reisezeit = "Nein"

Example:

Nr.    Reisezeit    Stunden

1           Nein               5

2          Nein               5

3               Ja               5

4               Ja               5

if menu = 1 =>sum Stunden = 20

if menu = 0 => sum Stunden = 10 

For setting menu 1 or 0 I have a slider in the design-part to switch.

Hope you can help me.

Re: if with a variable

HI

Try like this

In expression:

= If(menu = 1, Sum(Stunden), Sum({<Reisezeit = {'Nein'}>}Stunden))

Hope it helps

robert2012
New Contributor III

Re: if with a variable

Thank you,

but there is a mistake in the expression according to qv.

Community Browser