Page 1 of 1

dimensionelementprincipalname

Posted: Tue Feb 08, 2011 3:45 am
by telula_w
I have a month dimension that has Jan,Feb,Mar,etc with attributr Mthcount as 1,2,3 etc.
I am trying to write the code to get previous month name.

prevmth=numbertostring(ATTRN('Month',pmonth,'MthCount')-1);
prevmthname=DIMENSIONELEMENTPRINCIPALNAME('Month', prevmth);

The asciioutput for prevmthname is 1 when pmonth=1;
I thought that since the Month dimension elements are Jan,Feb,Mar, the DIMENSIONELEMENTPRINCIPALNAME would give Jan or Feb or Mar ?

How then would I get the output to show elementname Jan,Feb or Mar when I only have the attribute to go by?

Re: dimensionelementprincipalname

Posted: Tue Feb 08, 2011 3:58 am
by Alan Kirk
telula_w wrote:I have a month dimension that has Jan,Feb,Mar,etc with attributr Mthcount as 1,2,3 etc.
I am trying to write the code to get previous month name.

prevmth=numbertostring(ATTRN('Month',pmonth,'MthCount')-1);
prevmthname=DIMENSIONELEMENTPRINCIPALNAME('Month', prevmth);

The asciioutput for prevmthname is 1 when pmonth=1;
I thought that since the Month dimension elements are Jan,Feb,Mar, the DIMENSIONELEMENTPRINCIPALNAME would give Jan or Feb or Mar ?

How then would I get the output to show elementname Jan,Feb or Mar when I only have the attribute to go by?
Did you read the help file on what DimensionElementPrincipalName actually does?
This function returns the principal name of an element or element alias.
My emphasis. Element alias (which must be unique), not element attribute (which doesn't have to be, and which would make it impossible for TI to know which specific element you're referring to).

Rather than fluffing around with calculations (and to get around the problem of the first element's previous month being the last element of the dimension), why not simply assign the previous month's name as a string attribute to each of the 12 months and read it directly with an AttrS statement?

Re: dimensionelementprincipalname

Posted: Tue Feb 08, 2011 4:01 am
by telula_w
yup, realised the 'alias' bit after i posted this.
Solved the problem by turning the atrribute into an alias...