Leading zeros in AsciiOutPut being dropped

Post Reply
CRP0021
Posts: 11
Joined: Mon Aug 21, 2017 2:14 pm
OLAP Product: TM1
Version: 10.3
Excel Version: 2016

Leading zeros in AsciiOutPut being dropped

Post by CRP0021 » Thu Aug 29, 2019 5:45 am

Hello everyone,
Just a quick question as I'm dealing with an issue which I'm sure has been solved but can't seem to find anything on this.

I'm doing an ASCIIOUTPUT and one of the fields is an account dimension. This account dimension has 6 digits and various accounts include leading zeros i.e. 000123, 000456, etc.

When exporting to .csv and opening the exported file it drops the leading zeros so the result of this account dim is 123, 456, etc.

Normally I'd output to a .txt and it wouldn't matter but the intent is to grab data from the .csv and copy and paste it to an upload file to an external system.

The account dim that I am exporting is being read from the variables tab on the TI i.e. vAccount.
The ASCIIOutPut looks like this ( sFile, vAccount, aaa, bbb, ccc, etc.)

The .csv I am exporting from TM1 is laid out exactly in the order and format required to make the copy/paste function fairly simple except for this small nuisance of the leading zeros being dropped.

Any advice would be much appreciated!
Cheers

Wim Gielis
MVP
Posts: 2259
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: Leading zeros in AsciiOutPut being dropped

Post by Wim Gielis » Thu Aug 29, 2019 5:54 am

Do not open the csv with Excel but rather Notepad++
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

lotsaram
MVP
Posts: 3317
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Leading zeros in AsciiOutPut being dropped

Post by lotsaram » Thu Aug 29, 2019 6:54 am

I'm pretty sure Wim is correct and this is just Excel trying to be "helpful" by converting anything that looks like a number into a number. This is decidedly unhelpful when dealing with date strings and account numbers.

If you open in notepad you can verify pretty easily that the account numbers are actually written to the file correctly but text editors are not great when you need to do things like insert or remove columns. To be able to edit the file in Excel don't just open it, use the "import from text file" function then you can specify to treat the column as text and not number.

Also be careful if you then save from Excel that your locale setting for CSV delimiter is the same as the original. We always have issues with users replacing commas with semi-colons and vice versa.
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.

tomok
MVP
Posts: 2631
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: Leading zeros in AsciiOutPut being dropped

Post by tomok » Thu Aug 29, 2019 10:48 am

Here's a better idea (at least I think so). Don't give your output file the .csv extension, use .txt or anything else. That way when you open it in Excel it will ask you how you want all the columns defined and then you can say "Text" for the Account column, which will leave your leading zeros. When you open a file in Excel with the .csv extension it doesn't ask you the format and just assumes anything numeric is a number and formats it as such, meaning you lose the leading zeros.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/

Wim Gielis
MVP
Posts: 2259
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: Leading zeros in AsciiOutPut being dropped

Post by Wim Gielis » Sat Aug 31, 2019 9:35 am

Or, if your goal is to open in Excel rather than Notepad, do an AsciiOutput like for example:

Code: Select all

AsciiOutput( 'test.csv', vCostCenter, '=' | Char(34) | vAccount | Char(34), NumberToString( vValue ));
Ascii character 34 is a double quote so this is equivalent but somewhat more difficult to write:

Code: Select all

AsciiOutput( 'test.csv', vCostCenter, '="' | vAccount | '"', NumberToString( vValue ));
Have a look at DataSourceAsciiDelimiter and DataSourceAsciiQuoteCharacter as well.

Originally posted here: http://www.wimgielis.com/tm1_asciioutputtoexcel_EN.htm
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

Post Reply