Page 1 of 1

Add two attribute and display sum as new attribute in cube

Posted: Tue Jun 21, 2011 11:05 am
by k2g
Hi Friends,

I am new to TM1(working since last one month) and need your help. The Scenario is:

I have four dimension Dimension1, Dimension2, Dimension3 and Dimension4( in order) in cube 'CubeName'.
attribute1, attribut2, attribute3 and attribute4 are four attribute of Dimension4.

In Data procedure tab, for loading data in cube i have following code.
CELLPUTN(elmAttribute1,CubeName, varDimension1, varDimension2, varDimension3, 'attribute1');
CELLPUTN(elmAttribute2,CubeName, varDimension1, varDimension2, varDimension3, 'attribute2');
CELLPUTN(elmAttribute3,CubeName, varDimension1, varDimension2, varDimension3, 'attribute3');
CELLPUTN(elmAttribute4,CubeName, varDimension1, varDimension2, varDimension3, 'attribute4');

Data is loaded successfully in cube. Here is my problem:
1, 2 ,3, 4 are four attribute in Dimension2.Now I added two attribute A and B in Dimension 2. Attribute A should store sum of value corresponding to 1 and 2. Similarly B should store sum of value of 3 and 4.So When i choose A in Cube, it should show sum value of 1 and 2 for attribute1,attribute2, attribut3 and attribute4. Similarly for B.
I changes the TI code as follow:
CELLPUTN(elmAttribute1,CubeName, varDimension1, varDimension2, varDimension3, 'attribute1');
IF((varDimension2=1)%(varDimension2=2));
sumA=CELLGETN(CubeName, varDimension1, 'A', varDimension3, 'attribute1');
sumA=sumA+varDimension2;
ENDIF;
CELLPUTN(sumA,CubeName, varDimension1, 'A', varDimension3, 'attribute1');
IF((varDimension2=3)%(varDimension2=4));
sumB=CELLGETN(CubeName, varDimension1, 'B', varDimension3, 'attribute1');
sumB=sumB+varDimension2;
CELLPUTN(sumA,CubeName, varDimension1, 'B', varDimension3, 'attribute1');
ENDIF;

Similarly for attribute2, attribute3, attribute4. But this is not giving the right result for A and B :oops: .
Please take a look and give your suggestion if something wrong is in above code.
Thanks.

Re: Add two attribute and display sum as new attribute in cu

Posted: Tue Jun 21, 2011 10:48 pm
by Martin Ryan
For a start I think you're using "attribute" in the wrong way here. I think you mean measure. Attributes are pieces information held about an element. For example you might have a Staff Name attribute for Employee Number in the Employee dimension. Or a Fuel Type attribute for each car in the Vehicle dimension. Or Account Name for each of the Account Codes in the Chart of Accounts dimension.

Also, another aside, as far as TI is concerned when you are setting up attributes you should be using attrinsert and attrputs or attrputn, not cellputn. While strictly speaking you can do it this way it becomes less obvious what you're doing.

But coming to your specific question all you need is a consolidation. If elements "A" and "B" are N elements in Dimension2 then all you need do is create "C" as a consolidation of "A" + "B".

At the moment it looks like you have written some that pulls from one place then overwrites the same place with the number. I.e. B=B+A. While this will work, you'll end up overwriting B so obviously it's no longer going to be the sum of B+A when you look at the new numbers.

Martin

Re: Add two attribute and display sum as new attribute in cu

Posted: Thu Jun 23, 2011 1:28 pm
by k2g
Thanks Martin,
I will try what you said.