Determining if an alias exists in a dimension

Post Reply
dan.kelleher
Community Contributor
Posts: 128
Joined: Wed Oct 14, 2009 7:46 am
OLAP Product: TM1
Version: 9.4
Excel Version: 11
Location: London

Determining if an alias exists in a dimension

Post by dan.kelleher »

Hi,

In a TI process I want to add an element, say variable X, to a dimension if the element name doesn't exist (using Dimix, straightforward) and if no element has variable X as an alias within the same dimension.

I know that trying the addition will result in an error if an alias with the same name exists, and I also know I can use a while loop to test if each element's alias is the same, but is there an easier way using the inbuilt rule or Ti functions? From what I can see there is not, and I want to avoid error messages, however harmless, appearing in the message log unnecessarly.

Thanks,

Dan
jstrygner
MVP
Posts: 195
Joined: Wed Jul 22, 2009 10:35 pm
OLAP Product: TM1
Version: 9.5.2 FP3
Excel Version: 2010

Re: Determining if an alias exists in a dimension

Post by jstrygner »

Dan,

If you test via DimIx, if an element exists in a Dimension the function checks both basic names of elements and alias names.
So if there is an element with basic name or alias equal to 'X', DimIx will return index of such an element.

You would need iteration if you need to check for a text attribute that does need to be unique, but that is not your case from what I understand.

HTH
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Determining if an alias exists in a dimension

Post by tomok »

The ElementName argument of DIMIX, i.e., DIMIX(DimName,ElementName) can either be an actual element name OR an alias so if you DIMIX with the element you want to add it will return a value of greater than 1 if either that actual element already exists or it is an alias of another element that already exists.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
dan.kelleher
Community Contributor
Posts: 128
Joined: Wed Oct 14, 2009 7:46 am
OLAP Product: TM1
Version: 9.4
Excel Version: 11
Location: London

Re: Determining if an alias exists in a dimension

Post by dan.kelleher »

Thanks!
lotsaram
MVP
Posts: 3706
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Determining if an alias exists in a dimension

Post by lotsaram »

dan.kelleher wrote:Hi,

In a TI process I want to add an element, say variable X, to a dimension if the element name doesn't exist (using Dimix, straightforward) and if no element has variable X as an alias within the same dimension.

I know that trying the addition will result in an error if an alias with the same name exists, and I also know I can use a while loop to test if each element's alias is the same, but is there an easier way using the inbuilt rule or Ti functions? From what I can see there is not, and I want to avoid error messages, however harmless, appearing in the message log unnecessarly.

Thanks,

Dan
I think I get what you're trying to do an yes there is an easier way than looping through all attributes for the member and checking against the values for DTYPE 'AA'. Here is some (untested) code which check against both DIMIX and DimensionElementPrincipalName

Code: Select all

## This code on META DATA ##
IF( DIMIX(cDim, sNewEle) = 0 );
  # the new element is unique, let's add it
  DimensionElementInsert(cDim, '', sNewEle, 'N');
Else;
  sPrincipalNm = DimensionElementPrincipalName(cDim, sNewEle);
  IF( sNewEle @= sPrincipalNm );
    # the new element matches the name of an already exusting element so we can't add it
    ItemReject(sNewEle | ' matches a pre-existing element principal name');
  Else;
    # the new element matches the alias of an already exusting element so we can't add it
    ItemReject(sNewEle | ' matches an alias value of element ' | sPrincipalNm);
  EndIF;
EndIF;
Post Reply