Adding attributes only to newly created elements

Post Reply
michalb
Posts: 18
Joined: Thu Dec 03, 2020 3:45 pm
OLAP Product: TM1
Version: 2.1
Excel Version: 2016

Adding attributes only to newly created elements

Post by michalb »

Hello,

Please bear in mind I am a new TM1 user, so following question might look silly for you.

There is a process in my model that runs daily and imports products (vProduct) from .csv file to a product dimension (V_Dimension). Then it adds attribute 'Product Status' value as 'Active' to every product from source Let's simplify that there are no consolidations in this dimension.

Metadata:
DimensionElementInsert(V_Dimension, '', vProduct, 'N');
Data:
AttrPutS('Active',V_Dimension,vProduct,'Product Status');
That .csv file contains a lot of products, some of them are indeed 'Active' some of them not. To manage this I created also dictionary cube that allows users to modify attributes and process that update atrributes based on that dictionary cube. But the process described at the beggining obviously overrite all the newly created attributes.

What I want to do is to add 'Active' attribute only to new elements from source, that weren't present in V_Dimension. What is the best practise to do this? Should I create somewhere a loop through V_Dimension and somehow flag existing products just not to insert attributes for them?

regards
Last edited by michalb on Mon Dec 07, 2020 3:37 pm, edited 1 time in total.
User avatar
gtonkin
MVP
Posts: 1261
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: Adding attributes only to newly created

Post by gtonkin »

Anything new i.e. created in Metadata would have a blank/empty 'Product Status'.
You could check in Data if the attribute is blank then update it otherwise don't.

If you have blanks existing in 'Product Status' this would obviously not work.

Plan B may be to use the Direct functions and insert the element and update the attribute in Data.
BR, George.

Learn something new: MDX Views
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: Adding attributes only to newly created

Post by declanr »

Or create a temporary static subset in the prolog of all Products that exist when the process starts.
Then in the data tab use SubsetElementGetIndex and if it returns a zero then it is a newly added Product.
Declan Rodger
lotsaram
MVP
Posts: 3703
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Adding attributes only to newly created

Post by lotsaram »

Many ways to skin a cat.

Or loop through all products in the Prolog tab and set the status to empty or "Inactive" with AttrPutS function. Then in the Data tab set status "Active" with AttrPutS. This way you can be sure that only products present in the file will have status "Active".

(Note: this isn't quite what you asked for "Only flag newly created products as active". But I think it is the end result that you want).
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
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: Adding attributes only to newly created

Post by tomok »

lotsaram wrote: Fri Dec 04, 2020 11:03 am Or loop through all products in the Prolog tab and set the status to empty or "Inactive" with AttrPutS function. Then in the Data tab set status "Active" with AttrPutS.
Or create a view on the }ElementAttributes_Products dimension with just that one attribute and do a ViewZeroOut. This will likely be the fastest option unless the dimension has just a few elements. The overhead of creating and destroying the view might exceed the time needed to loop and do a CellPutS on every element if the dimension is really small.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
lotsaram
MVP
Posts: 3703
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Adding attributes only to newly created

Post by lotsaram »

tomok wrote: Fri Dec 04, 2020 11:20 am The overhead of creating and destroying the view might exceed the time needed to loop and do a CellPutS on every element if the dimension is really small.
My you're up early.
Yep. That is indeed my experience. Quite often looping (or even nested looping) without the benefit of zero supression is actually much faster than using a view due to avoiding the overhead of creating, registering and destroying objects.
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
michalb
Posts: 18
Joined: Thu Dec 03, 2020 3:45 pm
OLAP Product: TM1
Version: 2.1
Excel Version: 2016

Re: Adding attributes only to newly created

Post by michalb »

lotsaram wrote: Fri Dec 04, 2020 11:03 am
Or loop through all products in the Prolog tab and set the status to empty or "Inactive" with AttrPutS function. Then in the Data tab set status "Active" with AttrPutS. This way you can be sure that only products present in the file will have status "Active".

(Note: this isn't quite what you asked for "Only flag newly created products as active". But I think it is the end result that you want).
Indeed, this is not quite what I wanted to achive, because in the .csv file there are also 'Inactive' products, which are going to be flag as 'Inactive' in mentioned Dictionary Cube.
AttrPutS in Data tab will flag them again as 'Active' I guess.
Please note that both in V_Dimension and .csv file we have all the products existing (active and inactive). The thing is in .csv file we have new products added every day which are needed to be added to V_Dimension and have autmatically added attribute 'Active' (which can be later changed in Ditcionary cube).

I think I'll try with @lotsaram solution, however, I am not quite sure what 'static subset' means yet :)
@gtonkin ideas are nice too, but indeed I have some blanks existing in 'Product Status' and I am not familiar with 'direct functions'

Update:

Prolog:
V_Dimension='Test Product';

V_MDX='{TM1SUBSETALL( ['|V_Dimension|'] )}';
V_SubsetName='Products from dimension';

SubsetCreatebyMDX(V_SubsetName, V_MDX, 1);
SubsetMDXSet( V_Dimension, V_SubsetName, '' );
Metadata:
DimensionElementInsert(V_Dimension, '', vProduct, 'N');
Data:
V_Index=SubsetElementGetIndex(V_Dimension, V_SubsetName, vProduct, 1);

If(V_Index=0);
AttrPutS('Active',V_Dimension,vProduct,'Attribute test');
Endif;
works just fine for me. thanks for your responses
Post Reply