Removing leading\trailing zeroes in TM1

Post Reply
jack_008
Posts: 12
Joined: Wed Sep 28, 2016 2:20 pm
OLAP Product: TM1
Version: 10.3
Excel Version: Excel 2013

Removing leading\trailing zeroes in TM1

Post by jack_008 »

How can I remove leading\trailing zeroes ?

for eg: I have a order ID- 000023567 in a source file. So,In order to move only the 23567 portion of the order ID to the cube, what function or steps I can follow in TI Process to achieve the result? Also, the number of zeroes can vary for different order IDs.

Thanks in advance for the help.
User avatar
qml
MVP
Posts: 1096
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: Removing leading\trailing zeroes in TM1

Post by qml »

First of all - this is the wrong subforum, but I'm sure an Admin will kindly move the thread.

Stripping off zeroes can be done in a few ways, but I would generally convert the string to a number and then back to a string again:

Code: Select all

sShortOrderID = TRIM( STR( NUMBR( vLongOrderID ), 32, 0 ) );
Kamil Arendt
declanr
MVP
Posts: 1827
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: Removing leading\trailing zeroes in TM1

Post by declanr »

Sadly TM1 doesn't have a Replace function - if it did you could just replace 0 with blank.
For leading zeroes in a purely numeric string you can just convert to a number and then back to string NumberToString ( StringToNumber ( vRecord ) )
But that obviously doesn't work for trailing zeroes and can't be used if you have any string in the record.

The all encompassing option is to loop each character and delete the zeroes.

Code: Select all

sReplace = '0';
sReplaceWith = '';
iCount = Long ( vRecord );
While ( iCount > 0 );
	If ( SubSt ( vRecord, iCount, 1 ) @= sReplace );
		vRecord = SubSt ( vRecord, 1, iCount - 1 ) | sRecplaceWith;
	EndIf;
	iCount = iCount - 1;
End;
Declan Rodger
declanr
MVP
Posts: 1827
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: Removing leading\trailing zeroes in TM1

Post by declanr »

Randomly popped into my head earlier that my previous code didn't factor in what comes after the changed character... something like below would be more useful should anyone see this in the future.

Code: Select all

sSuffix = '';
sReplace = '0';
sReplaceWith = '';
iCount = Long ( vRecord );
While ( iCount > 0 );
	If ( SubSt ( vRecord, iCount, 1 ) @= sReplace );
		vRecord = SubSt ( vRecord, 1, iCount - 1 ) | sReplaceWith | sSuffix;
	Else;
	         sSuffix = SubSt ( vRecord, iCount, 1 ) | sSuffix;
	EndIf;
	iCount = iCount - 1;
End;
Surprised no one pulled me up on this.
Declan Rodger
Post Reply