Page 1 of 1

TM1 if statement issue

Posted: Thu Mar 06, 2014 10:05 am
by ssadoglu
Hello,

I've been using TM1 10.2.I'm newbie. I have a problem related to the if function.
Here is my rule :

Code: Select all

['Brüt Kar' ] = (DB('Satýþ ve Maliyet', !Aylar, !products, 'Satýþ', !Senaryolar, !Yýllar, !Ülkeler, !Stroes)
              + DB('Satýþ ve Maliyet', !Aylar, !products, 'Maliyet', !Senaryolar, !Yýllar, !Ülkeler, !Stroes));

['Sales' ] = N: DB('Satýþ ve Maliyet', !Aylar, !products, 'Satýþ', !Senaryolar, !Yýllar, !Ülkeler, !Stroes);

['Gider' ] = N: DB('gider', !Aylar, 'Toplam Giderler', !products, !Stroes, !Senaryolar, !Ülkeler, !Yýllar);

['Toplam Maliyet'] = N: DB('Satýþ ve Maliyet', !Aylar, !products, 'Maliyet', !Senaryolar, !Yýllar, !Ülkeler, !Stroes);

['Net Kar' ]  = N: (['Sales' ] - ( ['Gider' ] + ['Toplam Maliyet' ] ));

['Net Zarar'] = N:  IF(['Net Kar'] >0, 0, CONTINUE);
['Net Zarar'] = N:  IF(['Net Kar'] <0, ['Net Kar'], CONTINUE);

Net Kar is less than zero value. Net Kar would be zero value and Net Zarar would be equal first value of "Net Kar".

E.g :

First statement :
Net Kar :- 1200
Net Zarar : NULL
Second statement:
Net Kar : 0
Net zarar : -1200




Thanks in advance,

Kind Regards,

Re: TM1 if statement issue

Posted: Thu Mar 06, 2014 10:57 am
by David Usherwood
Your first rule sets Net Zarar based on Net Kar being positive, if not the second rule applies. Net Kar won't be affected by either rule as it's set in the line above. Remember rules are declarative, not procedural (like Excel formulae) - the first assignment which applies is the one which is used.

Code: Select all

['Net Kar' ]  = N: (['Sales' ] - ( ['Gider' ] + ['Toplam Maliyet' ] ));
['Net Zarar'] = N:  IF(['Net Kar'] >0, 0, CONTINUE);
['Net Zarar'] = N:  IF(['Net Kar'] <0, ['Net Kar'], CONTINUE);

Re: TM1 if statement issue

Posted: Thu Mar 06, 2014 11:38 am
by ssadoglu
David Usherwood wrote:Your first rule sets Net Zarar based on Net Kar being positive, if not the second rule applies. Net Kar won't be affected by either rule as it's set in the line above. Remember rules are declarative, not procedural (like Excel formulae) - the first assignment which applies is the one which is used.

Code: Select all

['Net Kar' ]  = N: (['Sales' ] - ( ['Gider' ] + ['Toplam Maliyet' ] ));
['Net Zarar'] = N:  IF(['Net Kar'] >0, 0, CONTINUE);
['Net Zarar'] = N:  IF(['Net Kar'] <0, ['Net Kar'], CONTINUE);
Hi David,

This rule isn't working. So I mean finally Net Kar must be zero value. But , it's not working. I want to do like below. if I work above "if condition" I'm getting the following result.
Net Kar : - 1200
Net zarar : -1200

Finally , I want to do :
if Net Kar < 0 ;

Net Kar : 0
Net zarar : -1200

Thanks , regards,

Re: TM1 if statement issue

Posted: Thu Mar 06, 2014 11:58 am
by David Usherwood
But you set Net Kar in the first rule and you can't then change it later - in fact your later rules only affect Net Zarar anyway. Be clear - Rules are declarative not procedural - once a rule applies that's it.

Re: TM1 if statement issue

Posted: Thu Mar 06, 2014 12:14 pm
by ssadoglu
David Usherwood wrote:But you set Net Kar in the first rule and you can't then change it later - in fact your later rules only affect Net Zarar anyway. Be clear - Rules are declarative not procedural - once a rule applies that's it.
Ok. How can I modify my rule? I'm a few confused.

Thanks & Regards,

Re: TM1 if statement issue

Posted: Thu Mar 06, 2014 1:07 pm
by David Usherwood
What's the business problem you are trying to solve?

Re: TM1 if statement issue

Posted: Thu Mar 06, 2014 1:35 pm
by ssadoglu
David Usherwood wrote:What's the business problem you are trying to solve?
Hello David,

OK. Like you said you are correct. I've changed the first line within rule. I've defined different column except "Net Kar". it works.

Kind regards,

Re: TM1 if statement issue

Posted: Fri Mar 07, 2014 11:50 am
by roy2087
Hi,

How about using this rule:-

['Net Zarar'] = N: IF(['Net Kar'] > 0, 0 , ['Net Kar'] );


Regards,
Roy.