Dynamic Assignment of Variable Names

Post Reply
User avatar
Steve Vincent
Site Admin
Posts: 1054
Joined: Mon May 12, 2008 8:33 am
OLAP Product: TM1
Version: 10.2.2 FP1
Excel Version: 2010
Location: UK

Dynamic Assignment of Variable Names

Post by Steve Vincent »

Not sure if this can be done in TI or not, but it'd be damn helpful if it could.

I have a need to export data using asciioutput in a tabular format, with variables down the left and months across the top. Normal export like this would put one value per line, so the same variables that had data against 200 months would create 200 seperate lines of data.

I could manually create 200 variables (M1, M2, M3 etc) and use CellGetN to grab the number, but i'd prefer to write a loop that goes through the subset of months i'm interested in, iterates the variable name and assigns the value that way. TI doesn't seem to want to do this tho, something along these lines will not save.

Code: Select all

#test code for dynamic variable names
nSub = 1;
While ( nSub <= 5 );
    'M' | NumberToString (nSub) = nSub;
End;
It doesn't like anything other than "hardcoded" variable names. Expand can help but only if they are in the variables tab - i can't iterate the number there so its of little use. Anyone know of a different way to approach this, or am i stuck with lots of lines of code?

TIA :)
If this were a dictatorship, it would be a heck of a lot easier, just so long as I'm the dictator.
Production: Planning Analytics 64 bit 2.0.5, Windows 2016 Server. Excel 2016, IE11 for t'internet
User avatar
Martin Ryan
Site Admin
Posts: 1989
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Re: Dynamic Assignment of Variable Names

Post by Martin Ryan »

Yeah, this is annoying. I've wanted to do it quite a few times myself - effectively have an array in TI. The only workaround I've found is creating a temporary dimension that then stores the variable data as an attribute. It's effective, but I don't really like it, as I'd like the variables to be internal to the TI process.

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
paulsimon
MVP
Posts: 808
Joined: Sat Sep 03, 2011 11:10 pm
OLAP Product: TM1
Version: PA 2.0.5
Excel Version: 2016
Contact:

Re: Dynamic Assignment of Variable Names

Post by paulsimon »

Steve

A few things occur

1) If you want a tabular report from TM1, is there any reason why you can't use Excel and Print Report/VBA to produce it?

2) As I understand it, your data source is a view, which has a row with an element from each dimension, including the months dimension, with its 200 elements, and then a value. You want a report which has the elements from all dimensions except months on the rows, and months across the top as columns.

If you are running on 9.4 and have access to long strings, then potentially you could build up your row as a string, and asciioutput at break of whatever dimensions are before month. If you don't need to output all 200 months but just a selection of them, then even in 9.x this approach could work.

You could drive the process from a view which just has the Total Months consol element, or whatever element will give all combinations of the other dimensions. As you read each record it, you could then get the appropriate months data via CellGetN.

Regards


Paul Simon
Post Reply