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 »

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: 712
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 »

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 »

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: 1202
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: Stuck on a if Condition.. too silly

Post by gtonkin »

As Michel said, you need ANDs , not ORs i.e. not blank and not N/A and not 0 etc.
declanr
MVP
Posts: 1815
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 »

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: 3122
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Stuck on a if Condition.. too silly

Post by Wim Gielis »

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

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
User avatar
Michel Zijlema
Site Admin
Posts: 712
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 »

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 »

Thanks. That was stupid of me.
Post Reply