Variable IF statement in a TI Process

Post Reply
JJ2
Posts: 19
Joined: Sun May 09, 2010 11:28 pm
OLAP Product: TM1
Version: 9.5
Excel Version: 2007

Variable IF statement in a TI Process

Post by JJ2 »

Hi Everyone, I have a very simple question. I'm using a TI process to create a hierarchical dimension from an ODBC excel source. I want to create a new variable (to be used as a consolidation/roll-up) with an IF statement based on the values in the Country dimension being Germany or France. So if the value is Germany or France then the variable (region) value should say Germany or France. Any other value in the country element should state 'Other'. The syntax I'm using in the Region variable is as follows:
IF (Country @= 'Germany');
(Region @='Germany');
ELSEIF (Country @= 'France');
(Region @='France');
ELSE (Region @= 'Other');
ENDIF;

Sorry for the simplicity of the question and the syntax shown above, very new to TM1. All responses are appreciated. Thanks
tomok
MVP
Posts: 2832
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Variable IF statement in a TI Process

Post by tomok »

IF (Condition1);
Statement1;
ELSIF (Conditon2);
Statement2;
ELSE;
Statement3;
ENDIF;
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
User avatar
Martin Ryan
Site Admin
Posts: 1988
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Re: Variable IF statement in a TI Process

Post by Martin Ryan »

JJ2 wrote: IF (Country @= 'Germany');
(Region @='Germany');
ELSEIF (Country @= 'France');
(Region @='France');
ELSE (Region @= 'Other');
ENDIF;
'@=' is for comparing two variables, not for assigning values to variables. So the above should be

IF (Country @= 'Germany');
Region ='Germany';
ELSEIF (Country @= 'France');
Region ='France';
ELSE;
Region = 'Other';
ENDIF;

You could also do
if(country@='Germany' % country@='France');
region=country;
else;
region='Other';
endif;

Martin
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer
User avatar
Alan Kirk
Site Admin
Posts: 6610
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Variable IF statement in a TI Process

Post by Alan Kirk »

JJ2 wrote:Hi Everyone, I have a very simple question. I'm using a TI process to create a hierarchical dimension from an ODBC excel source. I want to create a new variable (to be used as a consolidation/roll-up) with an IF statement based on the values in the Country dimension being Germany or France. So if the value is Germany or France then the variable (region) value should say Germany or France. Any other value in the country element should state 'Other'. The syntax I'm using in the Region variable is as follows:
IF (Country @= 'Germany');
(Region @='Germany');
ELSEIF (Country @= 'France');
(Region @='France');
ELSE (Region @= 'Other');
ENDIF;

Sorry for the simplicity of the question and the syntax shown above, very new to TM1. All responses are appreciated. Thanks
You're mixing up your comparison and assigment operators. You use @= if you want to compare one string variable to another, and see whether the two match. (You just use = to compare numeric values.) If you want to assign a value to another variable (whether string or numeric) you just use the = operator. So the code that you have above should actually be:

Code: Select all

IF (Country @= 'Germany');
   Region ='Germany';
ELSEIF  (Country @= 'France');
    Region ='France';
ELSE 
    Region = 'Other';
ENDIF;
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
JJ2
Posts: 19
Joined: Sun May 09, 2010 11:28 pm
OLAP Product: TM1
Version: 9.5
Excel Version: 2007

Re: Variable IF statement in a TI Process

Post by JJ2 »

Thanks Martin! Your examples worked perfectly!
jstrygner
MVP
Posts: 195
Joined: Wed Jul 22, 2009 10:35 pm
OLAP Product: TM1
Version: 9.5.2 FP3
Excel Version: 2010

Re: Variable IF statement in a TI Process

Post by jstrygner »

Martin Ryan wrote: You could also do
if(country@='Germany' % country@='France');
region=country;
else;
region='Other';
endif;
Martin
Or:

Code: Select all

region=if(country@='Germany' % country@='France', country, 'Other');
Not tested in a TI, but the idea should work.
Post Reply