Planning Analytics

Planning Analytics

Get AI-infused integrated business planning

 View Only
  • 1.  PAW Hierarchies

    Posted 27 days ago

    Hello All -

    Context - I am doing a deep dive into Hierarchies. I'm using a test date range in a dimension (9/1/2024 - 9/14/2024) to create two alternative hierarchies. The Parent dimension are the dates in sequential order with a total of all dates at the top. The alternative hierarchies ("Alt Hier") are a Week and ITD hierarchy. I created the basic dimension for the two Alt Hier to test the build code. It worked perfectly. Next I converted the Week dimension TI process to create an alternative hierarchy. 

    Problem - The empty Hierarchy is created; however, the "week" consolidation elements are not created nor are the attributes added to the dimension. 

    I am using a on Premise PAW 2.0.77.1 and TM1-AW64-ML-RTM-11.0.0.28-0. 

    Below I have provided the expected output, the actual output and the two TI processes used. 

    Thank you in advance for any guidance. 


    image.png
    TI Process 1

    DimName = '_zzMasterTime';

    HierName = 'Week';

    cAttr1 = 'DayNumber';

    cAttr2 = 'Week';

     

    IF(DimensionExists(DimName)=1);

         DimensionDestroy(DimName);

         DimensionCreate(DimName);

    ELSE;

        DimensionCreate(DimName);

    ENDIF;

     

    sHier = HIERARCHYCREATE(DimName,HierName);

     

    AttrInsert(DimName, '', cAttr1, 'N');

    AttrInsert(DimName, '', cAttr2, 'S');

     

    cDayStart = '2024-09-01';

     cDayEnd = '2024-09-14';

     

     nEle = DAYNO(cDayStart);

     WHILE(1 = 1);

       sEle = TIMST(nEle, '\Y-\m-\d');

     

    HIERARCHYELEMENTINSERT(DimName,HierName, '', sEle, 'N');

     

        IF(sEle @= cDayEnd);

          BREAK;

      ELSE;

           nEle = nEle + 1;

        ENDIF;

     END;

    ##################################################################

    TI Process 2

    DimName = '_zzMasterTime';

    HierName = 'Week';

    ElCnt = DimSiz(DimName);

    nAttr1 = 'DayNumber';

    sAttr1 = 'Week';

    sElm = 1;

     While(sElm <= ElCnt);

         ElNm = ELEMENTNAME(DimName,HierName,sElm);

         WkDt =  TIMST(DAYNO(ElNm),'\Y-\m-\d');

          DayNum = DAYNO(WkDt);

          nOut = MOD(DayNum,7);

               IF(nOut = 2);

                    Con = WkDt | '-Wk';

       HierarchyElementInsert(DimName,HierName,'',Con,'S'); 

               ENDIF;

          sDim = EXPAND('%DimName%:%HierName%');

         ATTRPUTN(DayNum,sDim,ElNm,nAttr1);

         ATTRPUTS(Con,sDim,ElNm,sAttr1);

    sElm = sElm +1 ;

    END;

    --
    Regards,
    Kevin


  • 2.  RE: PAW Hierarchies

    Posted 26 days ago

    Hi Kevin,

    What does your main dimension (Dimension: _zzMasterTime, Hierarcy: _zzMasterTime) look like?  You are using DimSiz, which gets the count of elements in the main dimension.  If you want the element count from a hierarchy you should use:  ElementCount(dimension, hierarchy)

    next I am not seeing any code to actually add parent - child relationships.  This is done with:   HierarchyElementComponentAdd(DimName, HierName, ConsolidatedElName, ElName, ElWeight);

    Also, generally the structure is built in the prolog/metadata portion of the code, and attributes are updated in the data/epilog portion.  

    I hope some of this helps!



    ------------------------------
    Scott Brown
    ------------------------------



  • 3.  RE: PAW Hierarchies

    Posted 26 days ago
      |   view attached

    Hello Scott - First, thank you for looking at my question. I have uploaded a file that includes the code and screenshots of the PAW output.

    This is my first ask for support from the community, so I assumed a little to much in writing up the question. Therefore, before you look at the attached file, I need to explain the structure of my TI Processes. To build the full alternate hierarchy, I have three (3) TI processes.

    • Process 1 creates the hierarchy, inserts the days elements and creates the attributes.
    • Process 2 creates the consolidations based on a simple 'IF' statement.
    • Process 3 inserts the leaf elements created in Process 1 to a consolidation (e.g. 2024-09-14-Wk).

    The code and output for each of the base TIs are on pages 5-7. Pages 1 and 3 include the hierarchy and base code side-by-side. Pages 2 and 4 include the hierarchy and base code outputs side-by-side. 

    I also want to address your comment "generally the structure is built in the prolog/metadata portion of the code, and attributes are updated in the data/epilog portion". Its my understanding that this is true when the data is sourced outside of the TI process. I am creating the leaf elements in Process 1 with a While loop and  If statement. However, I am happy to stand corrected. 

    Table of Contents

    1. Process 1 TI Code:    Hierarchy and Consolidation Scenario
      • Creates Dimension, creates leaf elements and inserts into dimension and adds Attribute names 
    2. Process 1 Output  :    Hierarchy and Consolidation Scenario
      • Screen shots of dimension after running Process 1
    3. Process 2 TI Code:    Hierarchy and Consolidation Scenario
      • Creates Consolidations and puts attribute data into Attributes
    4. Process 2 Output  :    Hierarchy and Consolidation Scenario
      • Screen shots of dimension after running Process 2
      • Highlights that the Hier Scenario does not have the consolidation elements like the Cons scenario
    5. Scenario Cons - Process 1:      TI Code and Screenshot of Result
    6. Scenario Cons - Process 2:      TI Code and Screenshot of Result
    7. Scenario Cons - Process 3:      TI Code and Screenshot of Result

    The objective is to use the code from the Cons Scenario to create an Alternate Hierarchy of Weekending consolidations and have a primary hierarchy that is at the leaf level with on total consolidation. 

    Thank you for your help. 

    Kevin



      ------------------------------
      Kevin Fry
      ------------------------------

      Attachment(s)



    1. 4.  RE: PAW Hierarchies

      Posted 25 days ago

      Hi Kevin,

      This is what your main hierarchy looks like after your first process runs:

      Then in your second process you use:

      ElCnt = DimSiz(DimName);

      As your can see from the screen shot, the hierarchy (with the same name as the dimension) does not have any elements.  So the DimSiz is 0.
      For this code you would want to use: 
      ElCnt = ElementCount( DimName, HierName);

      For the attributes of the hierarchy you want to use:
      ElementAttrInsert(DimName, HierName, PrevAttr, AttrName, Type);
      ElementAttrPutN( Value, DimName, HierName, ElName, AttrName, [LangLocaleCode] );
      ElementAttrPutS( Value, DimName, HierName, ElName, AttrName, [LangLocaleCode] );

      You can use the Element Attribute and Element Count code for both dimension and hierarchy attributes.  The only code that needs to be different between the two processes is create function.



      ------------------------------
      Scott Brown
      ------------------------------



    2. 5.  RE: PAW Hierarchies

      Posted 25 days ago

      Note that currently if you create an attribute, it is present in all hierarchies, and you are not able to have different values for leaf level elements in those attributes.

      Here is the code to do what you wanted in a single process:

      #Section Prolog
      DimName = '_zzMasterTime';
      HierName = 'Week';
      cAttr1 = 'DayNumber';
      cAttr2 = 'Week';
       
      IF(DimensionExists(DimName)=1);
           DimensionDestroy(DimName);
           DimensionCreate(DimName);
      ELSE;
          DimensionCreate(DimName);
      ENDIF;
       
      sHier = HIERARCHYCREATE(DimName,HierName);
       
      HierarchyTopElementInsert( DimName, DimName, '', 'Total Days');
      HierarchyTopElementInsert( DimName, HierName, '', 'Total Weeks');
      ## Note that Root elments do not need their parent child defined.  Anything inserted with a regular insert is assumed to be a child of the root element.
       
       
      ElementAttrInsert( DimName, HierName, '', cAttr1, 'N' );
      ElementAttrInsert( DimName, HierName, '', cAttr2, 'S' );
      cDayStart = '2024-09-01';
      cDayEnd = '2024-09-14';
       
      nEle = DAYNO(cDayStart);
      sEle = TIMST(nEle, '\Y-\m-\d');
      ## Need something for the first days in case they are not started on day 2, so set it to the first date.
      Con = sEle | '-Wk';
      WHILE(1 = 1);
          sEle = TIMST(nEle, '\Y-\m-\d');
          DayNum = DAYNO(sEle);
          nOut = MOD(DayNum,7);
          If( nOut = 2);
              Con = sEle | '-Wk';
          EndIf;
          HIERARCHYELEMENTINSERT(DimName,DimName, '', sEle, 'N');
          HIERARCHYELEMENTINSERT(DimName,HierName, '', Con, 'C');
          HIERARCHYELEMENTINSERT(DimName,HierName, '', sEle, 'N');
          HierarchyElementComponentAdd( DimName, HierName, Con, sEle, 1 );
       
          ## I would probably add a count check here to stop the process after so many days,  in case there is a spelling error in the end date so the process is not stuck in a perpetual loop.
          IF(sEle @= cDayEnd);
            BREAK;
          ELSE;
             nEle = nEle + 1;
          ENDIF;
      END;
       
      #Section Metadata
       
      #Section Data
       
      #Section Epilog
       
      CON = '';
      nEleIndex = 1;
      nEleMax = ElementCount( DimName, HierName );
      While( nEleIndex <= nEleMax);
          ElNm = ElementName( DimName, HierName, nEleIndex );
          If( ElementLevel( DimName, HierName, ElNm ) = 0);
              DayNum = DayNo( ElNm );
              nOut = MOD( DayNum,7);
              If( nOut = 2 % CON @= '');
                  Con = ElNm | '-Wk';
              EndIf;
              ElementAttrPutN( DayNum, DimName, HierName, ElNm, cAttr1 );
              ElementAttrPutS( Con, DimName, HierName, ElNm, cAttr2 );
          EndIf;
          
          If( ElementLevel( DimName, HierName, ElNm ) = 1);
              DayNum = DayNo( Subst(ElNm,1,10));
              nOut = MOD( DayNum,7);
              Con = ElNm;
              ElementAttrPutN( DayNum, DimName, HierName, ElNm, cAttr1 );
              ElementAttrPutS( Con, DimName, HierName, ElNm, cAttr2 );
          EndIf;
          nEleIndex = nEleIndex + 1;
      End;    



      ------------------------------
      Scott Brown
      ------------------------------