Page 1 of 1

Variable IF statement in a TI Process

Posted: Sun Oct 17, 2010 6:11 pm
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

Re: Variable IF statement in a TI Process

Posted: Sun Oct 17, 2010 8:07 pm
by tomok
IF (Condition1);
Statement1;
ELSIF (Conditon2);
Statement2;
ELSE;
Statement3;
ENDIF;

Re: Variable IF statement in a TI Process

Posted: Sun Oct 17, 2010 8:48 pm
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

Re: Variable IF statement in a TI Process

Posted: Sun Oct 17, 2010 8:50 pm
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;

Re: Variable IF statement in a TI Process

Posted: Mon Oct 18, 2010 3:57 pm
by JJ2
Thanks Martin! Your examples worked perfectly!

Re: Variable IF statement in a TI Process

Posted: Tue Oct 19, 2010 8:34 am
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.