Count dimensions in a cube via TIA

Ideas and tips for enhancing your TM1 application
Post Reply
User avatar
Steve Vincent
Site Admin
Posts: 1048
Joined: Mon May 12, 2008 8:33 am
OLAP Product: TM1
Version: 10.2.2 FP1
Excel Version: 2010
Location: UK

Count dimensions in a cube via TIA

Post by Steve Vincent » Tue Aug 19, 2008 4:34 pm

Thought i'd start a thread to share useful bits of code, here's one i've stumbled upon whilst writing some archival TIs this afternoon.

TM1, and TI in particular has quite a lot of inbuilt functions but occasionally they miss a few (ELISANC in Excel for one). Although TI has DIMSIZ to count the number of elements in a dimension, there is nothing to count the number of dims in a cube. When trying to recreate a cube via TI, thats a pain because you need to know how many dims to create it with to be able to write a "CubeCreate" statement.

Below is a short piece of code that works that out for you;

Code: Select all

    DimMax = 16;
    DimLast = TabDim ( CubeName , DimMax );
    While ( DimLast @= '' );
        DimMax = DimMax - 1;
        DimLast = TabDim ( CubeName , DimMax );
    End;
  • DimMax is set to 16 because i know we don't have any cubes bigger than that. If you do, then just set that higher.
  • CubeName is a variable within the TI, in my case it's from a dimension subset that's the datasource for the TI.
It uses the fact that TABDIM returns a blank value when DimMax is higher than the total number of dims in the cube. By subtracting one from that each time until it finds a value, the DimMax variable will hold the maximum (therefore total) number of dims in the cube once it breaks out of the while loop.
If this were a dictatorship, it would be a heck of a lot easier, just so long as I'm the dictator.
Production: TM1 64 bit 10.2.2, Windows 2008/2012 Server. Excel 2010, IE11 for t'internet

Ptec
Posts: 15
Joined: Mon Mar 14, 2016 9:14 am
OLAP Product: TM1
Version: 10.2.2.0
Excel Version: 2013

Re: Count dimensions in a cube via TIA

Post by Ptec » Wed Oct 05, 2016 1:08 pm

Thank you very much! This one helped me out ;)

Wim Gielis
MVP
Posts: 1529
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1
Version: PAL 2.0
Excel Version: 2016
Location: Brussels, Belgium
Contact:

Re: Count dimensions in a cube via TIA

Post by Wim Gielis » Wed Oct 05, 2016 1:54 pm

Best regards,

Wim Gielis

Excel Most Valuable Professional, 2011-2014
http://www.wimgielis.com ==> 103 TM1 articles and a lot of custom code
Newest blog article: TM1 message log analysis with Power Query

Post Reply