Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
MayilVahanan

HI

PFA

Regards,

R.Mayil Vahanan

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

14 Replies
Not applicable
Author

try this

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

Anonymous
Not applicable
Author

Thank you for your answer!

And what about the sum?

er_mohit
Master II
Master II

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

hope it helps

Not applicable
Author

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

Anonymous
Not applicable
Author

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
Author

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.

Anonymous
Not applicable
Author

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.

MayilVahanan

HI

Try like this

In expression:

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

Hope it helps

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Anonymous
Not applicable
Author

Thank you,

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