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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

If condition in expression

I need help in making expression

Suppose I have months Oct2016, Nov2016 and Dec2016 and I have selected Oct2016

What I want is,

If (stock<=req)

then

                stock*30/req

else

                stock=stock-req

now if the above condition is not true say stock is greater than req then I want

if (stock<=req) //this time it would check for Nov2016 means stock value would come from this (stock=stock-req) and req value would be for Nov2016 and again the same condition

then

                stock*30/req

else

                stock=stock-req

and this same goes on till Dec2016

But if the condition is true for any month then I have variable A with fixed value = 30 and I want

A=A+20

Assuming that 20 is the result of condition which is true

How I can achieve this?

Thanks

4 Replies
shraddha_g
Partner - Master III
Partner - Master III

Not so clear..

Could you please explain by using some sample data and expected output?

Anonymous
Not applicable
Author

Month

Oct-16

Nov-16

Dec-16

Stock

2000

1000

500

Req

1000

500

1000

I have selected Oct2016

Now

If (stock<=req) // (2000<=1000) which is not true

Then

                stock*30/req // Here this would fail as 2000 is greater than 1000

Else

                stock=stock-req // 2000-1000=1000 and the resultant value 1000 is now stock for Nov2016

Now

If (stock<=req) // (1000<=500) which is again not true

Then

                stock*30/req // Here this would fail as 1000 is greater than 500

Else

                stock=stock-req // 1000-500=500 and the resultant value 500 is now stock for Dec2016

Now

If (stock<=req) // (500<=1000) which in this case is true

Then

                stock*30/req // Here it would be 500*30/1000 = 15

now this value 15 should get added in variable A which has value 30.

A=A+15 //  30+15=45

Anonymous
Not applicable
Author

A little change is highlighted

Month

Oct-16

Nov-16

Dec-16

Stock

2000

1000

500

Req

1000

500

1000

I have selected Oct2016

Now

If (stock<=req) // (2000<=1000) which is not true

Then

                stock*30/req // Here this would fail as 2000 is greater than 1000

Else

                stock=stock-req // 2000-1000=1000 and the resultant value 1000 is now stock for Nov2016

and variable A=30

Now

If (stock<=req) // (1000<=500) which is again not true

Then

                stock*30/req // Here this would fail as 1000 is greater than 500

Else

                stock=stock-req // 1000-500=500 and the resultant value 500 is now stock for Dec2016

and A=A+30 // 30+30 = 60

Now

If (stock<=req) // (500<=1000) which in this case is true

Then

                stock*30/req // Here it would be 500*30/1000 = 15

now this value 15 should get added in variable A which has value 60.

A=A+15 //  60+15=75

prithviram777
Partner - Contributor III
Partner - Contributor III

Hi Wahija,

You can try

If(Stock<=Required,((Stock*30)/Required)+50,Sum(Stock-Required))

Where i have considered 50 as A.

Hope it helps.

Thank you