Dimension Element Delete NOT Working

Post Reply
roy2087
Posts: 40
Joined: Wed Feb 06, 2013 9:53 am
OLAP Product: cognos tm1
Version: 10.1.1
Excel Version: 2007
Location: Bangalore,India

Dimension Element Delete NOT Working

Post by roy2087 »

Hi,

I have Dimension 2h_District.
2h_District has a TEXT Attribute , Company.
Now, I want to delete all the elements in 2h_District where Company in NULL.
Eg.

District Company
N201 IN10
N202 (Blank)

I wrote a Code in TI Metadata.

If
(
ATTRS('2h_District',vDistrict,'Company') @=' '
);

DimensionElementDelete('2h_District',vDistrict);
itemskip;
ENDIF;

Result should be:-
N202 should be deleted from 2h_District

But, this code is NOT working.
Can anyone help me please?

Regards,
Roy.
Tm1andTm1
Posts: 48
Joined: Thu Apr 11, 2013 7:47 am
OLAP Product: Cognos TM1
Version: 10.2
Excel Version: 2010

Re: Dimension Element Delete NOT Working

Post by Tm1andTm1 »

Hi Roy,

It seems you have used ATTRS widely in the project.
ATTRS is good function of TM1, but still very dangerous if used without caution.
declanr
MVP
Posts: 1828
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: Dimension Element Delete NOT Working

Post by declanr »

Roy,

Just stick an extra line in your TI process to do an asciioutput of whatever the AttrS does return and then you will see why it is not matching your conditions.


Tm1andTm1 wrote:Hi Roy,

It seems you have used ATTRS widely in the project.
ATTRS is good function of TM1, but still very dangerous if used without caution.
TM1andTM1,

I would say that this expands to every function within any code language... if you don't use functions correctly there will be issues.
This seems a normal way to use it though.
Declan Rodger
lotsaram
MVP
Posts: 3702
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Dimension Element Delete NOT Working

Post by lotsaram »

Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
What exactly do you mean by that? Please explain how ATTRS can be "dangerous".
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
Wim Gielis
MVP
Posts: 3230
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Dimension Element Delete NOT Working

Post by Wim Gielis »

lotsaram wrote:
Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
What exactly do you mean by that? Please explain how ATTRS can be "dangerous".
Attribute values could be empty for an alias (but that would not be an issue for text attributes, in that case it's empty and you (should) know it).
Best regards,

Wim Gielis

IBM Champion 2024-2025
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
Tm1andTm1
Posts: 48
Joined: Thu Apr 11, 2013 7:47 am
OLAP Product: Cognos TM1
Version: 10.2
Excel Version: 2010

Re: Dimension Element Delete NOT Working

Post by Tm1andTm1 »

lotsaram wrote:
Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
What exactly do you mean by that? Please explain how ATTRS can be "dangerous".

Lotsaram

It is difficult to put in words,
Well..... it would be your experience which can give you the answer of this question.....
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

Re: Dimension Element Delete NOT Working

Post by Steve Vincent »

roy2087 wrote: If (ATTRS('2h_District',vDistrict,'Company') @=' ' );
DimensionElementDelete('2h_District',vDistrict);
itemskip;
ENDIF;
Think you are missing an ELSE statement, try;

Code: Select all

If (ATTRS('2h_District',vDistrict,'Company') @=' ' );
    DimensionElementDelete('2h_District',vDistrict);
ELSE;
    itemskip;
ENDIF;

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
MSidat
Community Contributor
Posts: 110
Joined: Thu Aug 26, 2010 7:41 am
OLAP Product: TM1, PA
Version: PAL 2.0.8
Excel Version: 2016
Location: North West England

Re: Dimension Element Delete NOT Working

Post by MSidat »

Maybe others can correct me If I am wrong but I know TM1 is not Space sensitive when it comes to element names etc however it can be for Data.

As such you might want to search for '' instead of ' ' in ATTRS or always search for '' and wrap your attrs with a TRIM function.

Hope this helps.
Always Open to Opportunities
declanr
MVP
Posts: 1828
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: Dimension Element Delete NOT Working

Post by declanr »

Steve Vincent wrote: Think you are missing an ELSE statement, try;

Code: Select all

If (ATTRS('2h_District',vDistrict,'Company') @=' ' );
    DimensionElementDelete('2h_District',vDistrict);
ELSE;
    itemskip;
ENDIF;


Not sure without seeing what else is in the code but I had assumed it was meant to be along the lines of:

If the District doesn't have a company attribute - Delete the Element AND skip the rest of the code on that tab...
otherwise - continue with the rest of the code for the Elements that still exist.
Declan Rodger
lotsaram
MVP
Posts: 3702
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Dimension Element Delete NOT Working

Post by lotsaram »

Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.

....
It is difficult to put in words,
Well..... it would be your experience which can give you the answer of this question.....
No really in all seriousness. In your (I'm sure enormous) experience please do elucidate on how ATTRS can be a dangerous function and how do you suggest caution in its use versus wild abandon?
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
User avatar
jim wood
Site Admin
Posts: 3958
Joined: Wed May 14, 2008 1:51 pm
OLAP Product: TM1
Version: PA 2.0.7
Excel Version: Office 365
Location: 37 East 18th Street New York
Contact:

Re: Dimension Element Delete NOT Working

Post by jim wood »

Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
Erm, I'm a little stumped here. Surely CellPutS is more dangerous as not only can you update data cells you can also achieve the same as a ATTRS when sending data to control cubes?
Struggling through the quagmire of life to reach the other side of who knows where.
Shop at Amazon
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
rmackenzie
MVP
Posts: 733
Joined: Wed May 14, 2008 11:06 pm

Re: Dimension Element Delete NOT Working

Post by rmackenzie »

roy2087 wrote:I wrote a Code in TI Metadata.

If
(
ATTRS('2h_District',vDistrict,'Company') @=' '
);

DimensionElementDelete('2h_District',vDistrict);
itemskip;
ENDIF;
Although it is not the case with all TI functions, it is definitely the case with ATTRS that it is not a good coding practice in TI to put the function directly within the condition of an IF statement. Try these two examples in a test process and you will see that in the case of the first example, no error is thrown and, in fact, the 'false' clause is executed. IMHO this creates unacceptable risk:

Code: Select all

nResult = 1;

# no error thrown on next line even though dimension does not exist - condition just evaluates to FALSE
IF ( ATTRS ( 'Not_Exists', 'Me_Neither', 'Foo' ) @= 'Bar' );
  nResult = 2;

ELSE;
  nResult = 3;

ENDIF;

ItemReject ( 'Answer is: ' | NumberToString ( nResult ) );
The correct coding technique is to set a variable before the IF statement. In this case, TI will correctly throw an error:

Code: Select all

nResult = 1;

# error occurs on next line because no such dimension exists
sAttritbuteValue = ATTRS ( 'Not_Exists', 'Me_Neither', 'Foo' );

# this logic is never evaluated as process has aborted
IF ( sAttritbuteValue @= 'Bar' );
  nResult = 2;

ELSE;
  nResult = 3;

ENDIF;

ItemReject ( 'Answer is: ' | NumberToString ( nResult ) );
Using this technique in conjunction with the earlier advice to use AsciiOutput/ TextOutput commands on the problem attribute should help you debug your code.
Robin Mackenzie
roy2087
Posts: 40
Joined: Wed Feb 06, 2013 9:53 am
OLAP Product: cognos tm1
Version: 10.1.1
Excel Version: 2007
Location: Bangalore,India

Re: Dimension Element Delete NOT Working

Post by roy2087 »

Hi,

I have made some changes in the Data Source section.

Earlier, I was using "Cube View" as a Data Source,
but now I am using "Dimension Sub" as a Data Source.

In the Dimension(2h_District), I have made a subset which has only Leaf Level elements.
Then , I am using this following code in the Metadata Section..
**************************************************************
If
(
ATTRS('2h_District',vDistrict,'Company') @=' '
);

DimensionElementDelete('2h_District',vDistrict);
itemskip;
ENDIF;
*************************************************************

Phew..! It worked.
Did'nt know changing the Data Source would make such as a difference.
Thanks everyone!

Roy....
Tm1andTm1
Posts: 48
Joined: Thu Apr 11, 2013 7:47 am
OLAP Product: Cognos TM1
Version: 10.2
Excel Version: 2010

Re: Dimension Element Delete NOT Working

Post by Tm1andTm1 »

Hi roy2087,

Have you got the solution you require......? If not, please let me know
roy2087
Posts: 40
Joined: Wed Feb 06, 2013 9:53 am
OLAP Product: cognos tm1
Version: 10.1.1
Excel Version: 2007
Location: Bangalore,India

Re: Dimension Element Delete NOT Working

Post by roy2087 »

Yes, I have got the solution.
Post Reply