# New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

New Contributor II

## 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
Honored Contributor III

## Re: If condition in expression

Not so clear..

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

New Contributor II

## Re: If condition in expression

 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

New Contributor II

## Re: If condition in expression

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

New Contributor III

## Re: If condition in expression

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