Page 1 of 1

Count dimensions in a cube via TIA

Posted: Tue Aug 19, 2008 4:34 pm
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.

Re: Count dimensions in a cube via TIA

Posted: Wed Oct 05, 2016 1:08 pm
by Ptec
Thank you very much! This one helped me out ;)

Re: Count dimensions in a cube via TIA

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