Count dimensions in a cube via TIA

Ideas and tips for enhancing your TM1 application
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

Count dimensions in a cube via TIA

Post by Steve Vincent »

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: Planning Analytics 64 bit 2.0.5, Windows 2016 Server. Excel 2016, 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 »

Thank you very much! This one helped me out ;)
Wim Gielis
MVP
Posts: 3098
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Count dimensions in a cube via TIA

Post by Wim Gielis »

Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Post Reply