Stuck on a if Condition.. too silly

Post Reply
LutherPaul
Posts: 80
Joined: Tue Jun 04, 2013 3:35 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Stuck on a if Condition.. too silly

Post by LutherPaul » Wed Jun 07, 2017 5:01 pm

Hi Gurus,
I am stumped on a simple if condition which fails miserably. I am reading data from a csv file.
The first condition to check for blank works and fails checking 'N/A', <>0 and ='N'.
Can someone tell me where I am going wrong?

the condition translates to
if Proj_code is not blank or proj_code is not equal to 'N/A' or Proj_code is not equal '0' or if NewBuss is equal to 'N'

if ( Proj_code @<> '' % Proj_code @<> 'N/A' % Proj_code @<> '0' % NewBuss @= 'N') ;
-----
EndIf;

I have verified that the data is 'N/A', '0'. Dont understand why the OR condition fails. Can someone please help?

Thanks,
Paul.

User avatar
Michel Zijlema
Site Admin
Posts: 705
Joined: Wed May 14, 2008 5:22 am
OLAP Product: TM1, PALO
Version: both 2.5 and higher
Excel Version: 2003-2007-2010
Location: Netherlands
Contact:

Re: Stuck on a if Condition.. too silly

Post by Michel Zijlema » Wed Jun 07, 2017 5:48 pm

LutherPaul wrote:the condition translates to
if Proj_code is not blank or proj_code is not equal to 'N/A' or Proj_code is not equal '0' or if NewBuss is equal to 'N'

if ( Proj_code @<> '' % Proj_code @<> 'N/A' % Proj_code @<> '0' % NewBuss @= 'N') ;
-----
EndIf;

I have verified that the data is 'N/A', '0'.
So you're saying the data is 'N/A', '0' and you're checking on is not equal to 'N/A' or is not equal to '0'.
Isn't that your issue? Otherwise you need to be a bit more clear on what you expect to happen inside and outside of the if statement.

Michel

LutherPaul
Posts: 80
Joined: Tue Jun 04, 2013 3:35 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Re: Stuck on a if Condition.. too silly

Post by LutherPaul » Wed Jun 07, 2017 6:14 pm

Thanks Michel for replying.

I have bad data coming in with values like 'N/A', '0', 'ASDF', which I want to avoid.

When the data is not in ('N/A', '0', 'ASDF'), I want my if to work else, nothing.

Hope I am clear.

Thanks,
Paul.

User avatar
gtonkin
MVP
Posts: 717
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: PAL 2.0.3
Excel Version: 2016 64-bit
Location: JHB, South Africa
Contact:

Re: Stuck on a if Condition.. too silly

Post by gtonkin » Wed Jun 07, 2017 6:18 pm

As Michel said, you need ANDs , not ORs i.e. not blank and not N/A and not 0 etc.

declanr
MVP
Posts: 1626
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: Stuck on a if Condition.. too silly

Post by declanr » Wed Jun 07, 2017 6:20 pm

Code: Select all

if ( Proj_code @<> ''  % Proj_code @<> 'N/A'  % Proj_code @<> '0' % NewBuss @= 'N') ; 
With code like this you are sort of applying a double negative... if the project code is "N/A" it can't also be blank so by using an or on it; the "N/A" gets through as it is not blank or 0.

Its sometimes easier to say if something is equal to such and such then itemskip.
Declan Rodger

Wim Gielis
MVP
Posts: 2208
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: Office 365 - latest
Location: Brussels, Belgium
Contact:

Re: Stuck on a if Condition.. too silly

Post by Wim Gielis » Wed Jun 07, 2017 6:31 pm

declanr wrote:

Code: Select all

if ( Proj_code @<> ''  % Proj_code @<> 'N/A'  % Proj_code @<> '0' % NewBuss @= 'N') ; 
With code like this you are sort of applying a double negative... if the project code is "N/A" it can't also be blank so by using an or on it; the "N/A" gets through as it is not blank or 0.

Its sometimes easier to say if something is equal to such and such then itemskip.
True. In Metadata and Data tabs with more than a handful lines of code, I tend to use Itemskip and Itemreject first.
All other cases that remain will be treated with the remaining code.
Best regards,

Wim Gielis

Excel Most Valuable Professional, 2011-2014
http://www.wimgielis.com ==> 109 TM1 articles and a lot of custom code
Newest blog article: Set up a TM1 model with AutoHotKey as a service or application

User avatar
Michel Zijlema
Site Admin
Posts: 705
Joined: Wed May 14, 2008 5:22 am
OLAP Product: TM1, PALO
Version: both 2.5 and higher
Excel Version: 2003-2007-2010
Location: Netherlands
Contact:

Re: Stuck on a if Condition.. too silly

Post by Michel Zijlema » Wed Jun 07, 2017 6:57 pm

declanr wrote:Its sometimes easier to say if something is equal to such and such then itemskip.
I second that. To me it was not clear whether the If statement enclosed an ItemSkip or the actionable code...
I would reverse the conditions and put an ItemSkip inside the if and the actionable code after the endif.
Otherwise (the actionable code still within the if) the condition should I assume be:

Code: Select all

if ( (Proj_code @<> ''  & Proj_code @<> 'N/A'  & Proj_code @<> '0') % NewBuss @= 'N') ;
Michel

LutherPaul
Posts: 80
Joined: Tue Jun 04, 2013 3:35 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Re: Stuck on a if Condition.. too silly

Post by LutherPaul » Wed Jun 07, 2017 7:53 pm

Thanks. That was stupid of me.

Post Reply