SubsetElementInsert - all items under roll up
-
- Regular Participant
- Posts: 194
- Joined: Thu May 30, 2013 1:41 pm
- OLAP Product: Cognos
- Version: Planning Analytics 2.0.7
- Excel Version: 2010
SubsetElementInsert - all items under roll up
I'm using a SubsetElementInsert in a TI process that creates source view for data transfer.
For example: SubsetElementInsert(vDimName,sSubset,'(P&L)',1); where P&L represents a roll up of profit and loss GL accounts.
However what I actually want is to list all the level 0 items under "(P&L)" instead of the rollup.
How should I code this?
Thanks in advance.
Kenneth
For example: SubsetElementInsert(vDimName,sSubset,'(P&L)',1); where P&L represents a roll up of profit and loss GL accounts.
However what I actually want is to list all the level 0 items under "(P&L)" instead of the rollup.
How should I code this?
Thanks in advance.
Kenneth
- gtonkin
- MVP
- Posts: 1199
- 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: SubsetElementInsert - all items under roll up
You would probably want to do this via MDX e.g.
Code: Select all
sMDX='{TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER( [<dim>].[(P&L)]}}, ALL, RECURSIVE )}, 0)}';
SubsetCreateByMDX(sSubset,sMdx);
-
- Regular Participant
- Posts: 194
- Joined: Thu May 30, 2013 1:41 pm
- OLAP Product: Cognos
- Version: Planning Analytics 2.0.7
- Excel Version: 2010
Re: SubsetElementInsert - all items under roll up
Unfortunately I got an error saying Syntax error at or near: "}, ALL, RECURSIVE )}, 0)}", character position 65 expression.
Below is how the view and subset are setup.
Moreover, I realize that in addition to N02PNL I also need to include N02BUD. Should I create sMDX2?
Many thanks.
Below is how the view and subset are setup.
Moreover, I realize that in addition to N02PNL I also need to include N02BUD. Should I create sMDX2?
Many thanks.
Code: Select all
IF (vDimName @= 'FINDW_Business_Unit');
SubsetElementInsert(vDimName,sSubset,'(ROY1+ROY2)',1);
ELSEIF( vDimName @= 'FINDW_Account');
sMDX='{TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER( [FINDW_Account].[N02PNL])}, ALL, RECURSIVE )}, 0)}';
SubsetCreateByMDX(sSubset,sMdx);
# Creates all N level elements within each dimension (default case)
ELSE;
vIndex = 1;
vIndexSub = 1;
WHILE(vIndex <= DIMSIZ(vDimName));
vElement = DIMNM(vDimName, vIndex);
IF(DTYPE(vDimName, vElement)@='N');
SubsetElementInsert(vDimName, sSubset,vElement, vIndexSub);
vIndexSub = vIndexSub +1;
ENDIF;
vIndex = vIndex + 1;
END;
ENDIF;
- gtonkin
- MVP
- Posts: 1199
- 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: SubsetElementInsert - all items under roll up
You can specify multiple items as a set and then drill them down.
Not always easy to get the syntax correct when you are typing straight into the forum but try this:
Not always easy to get the syntax correct when you are typing straight into the forum but try this:
Code: Select all
sMDX='{TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER( {[FINDW_Account].[N02PNL],[FINDW_Account].[N02BUD]}, ALL, RECURSIVE )}, 0)}';
SubsetCreateByMDX(sSubset,sMdx);
-
- Regular Participant
- Posts: 194
- Joined: Thu May 30, 2013 1:41 pm
- OLAP Product: Cognos
- Version: Planning Analytics 2.0.7
- Excel Version: 2010
Re: SubsetElementInsert - all items under roll up
Unfortunately this time I've got into "Unable to register subset" error.
I began with the section with SubsetCreate (vDimName, sSubset) and add dimensions one by one using IF and ElseIf, maybe that's my problem and the dimension using MDX be treated separately?
I don't know...
I began with the section with SubsetCreate (vDimName, sSubset) and add dimensions one by one using IF and ElseIf, maybe that's my problem and the dimension using MDX be treated separately?
I don't know...
- gtonkin
- MVP
- Posts: 1199
- 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: SubsetElementInsert - all items under roll up
Make sure you cleanup temporary subsets-one probably exists and will need to be destroyed before creating via MDX
-
- Regular Participant
- Posts: 194
- Joined: Thu May 30, 2013 1:41 pm
- OLAP Product: Cognos
- Version: Planning Analytics 2.0.7
- Excel Version: 2010
Re: SubsetElementInsert - all items under roll up
It's clean. All temp. view and subsets are empty.
I don't know. Will take a break and revisit it.
Thanks!
Kenneth
I don't know. Will take a break and revisit it.
Thanks!
Kenneth
- PavoGa
- MVP
- Posts: 617
- Joined: Thu Apr 18, 2013 6:59 pm
- OLAP Product: TM1
- Version: 10.2.2 FP7, PA2.0.9.1
- Excel Version: 2013 PAW
- Location: Charleston, Tennessee
Re: SubsetElementInsert - all items under roll up
Just a hint to make the code a little cleaner to view: the functions that return a set do not require the {} to work properly. The {} are redundant. Only around members are those required in order to return a set when a set is needed.
For instance:
Works as well as:
With regards to the code that is failing:
Here is the correction:
The {} needed to surround [FINDW_Account] and the first ) after [N02PNL] was removed. Hope this solves it for you.
For instance:
Code: Select all
TM1FILTERBYLEVEL( TM1DRILLDOWNMEMBER( {[FINDW_Account].[N02PNL],[FINDW_Account].[N02BUD]}, ALL, RECURSIVE ), 0)
Code: Select all
{TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER( {[FINDW_Account].[N02PNL],[FINDW_Account].[N02BUD]}, ALL, RECURSIVE )}, 0)}
Code: Select all
sMDX='{TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER( [FINDW_Account].[N02PNL])}, ALL, RECURSIVE )}, 0)}';
Code: Select all
sMDX='TM1FILTERBYLEVEL( TM1DRILLDOWNMEMBER( {[FINDW_Account].[N02PNL]}, ALL, RECURSIVE), 0)';
Last edited by PavoGa on Fri Apr 21, 2017 8:09 pm, edited 1 time in total.
Ty
Cleveland, TN
Cleveland, TN
-
- Regular Participant
- Posts: 194
- Joined: Thu May 30, 2013 1:41 pm
- OLAP Product: Cognos
- Version: Planning Analytics 2.0.7
- Excel Version: 2010
Re: SubsetElementInsert - all items under roll up
Thanks, the line works. But I still can't register the subset. After some testing I realize
SubsetCreateByMDX(sSubset, sMDX);
doesn't work when it being placed in a sequence of creating subset for each dimension in the cube to create a source view.
I tried using sSubset1 but not being able to assign it to the source view.
BTW, temporary view and subsets are all deleted before testing.
Still trying to get around it.
But thanks!
Kenneth
SubsetCreateByMDX(sSubset, sMDX);
doesn't work when it being placed in a sequence of creating subset for each dimension in the cube to create a source view.
I tried using sSubset1 but not being able to assign it to the source view.
BTW, temporary view and subsets are all deleted before testing.
Still trying to get around it.
But thanks!
Kenneth
Code: Select all
# cube info
sCube = 'FINDW_Ledger';
sSubset = 'source_transfer_ledger_to_obm_actuals_subset';
sView = 'source_transfer_ledger_to_obm_view';
#Recreate the Source View
IF(ViewExists(sCube, sView) = 1);
ViewDestroy(sCube,sView);
ENDIF;
ViewCreate(sCube, sView);
vSOldLogChanges = CubeGetLogChanges(sCube);
vTOldLogChanges = CubeGetLogChanges(tCube);
CubeSetLogChanges(sCube, 0);
CubeSetLogChanges(tCube, 0);
######## Create other subsets and Source View#########
vIndexDim = 1;
WHILE(TABDIM(sCube, vIndexDim) @<> '');
vDimName = TABDIM(sCube, vIndexDim);
#Subset Creation
IF(SubsetExists(vDimName, sSubset) = 1);
# if the subset already exists, destroy it for creation later
SubsetDestroy(vDimName,sSubset);
ENDIF;
# Create and add elements
SubsetCreate(vDimName, sSubset);
# Adding boundaries onto subsets
IF (vDimName @= 'FINDW_Account');
sMDX='{TM1FILTERBYLEVEL( TM1DRILLDOWNMEMBER( {[FINDW_Account].[N02PNL], [FINDW_Account].[N02BUD]}, ALL,
RECURSIVE), 0)}';
SubsetCreateByMDX(sSubset, sMDX);
#Creates all N level elements within each dimension (default case)
ELSE;
vIndex = 1;
vIndexSub = 1;
WHILE(vIndex <= DIMSIZ(vDimName));
vElement = DIMNM(vDimName, vIndex);
IF(DTYPE(vDimName, vElement)@='N');
SubsetElementInsert(vDimName, sSubset,vElement, vIndexSub);
vIndexSub = vIndexSub +1;
ENDIF;
vIndex = vIndex + 1;
END;
ENDIF;
ViewSubsetAssign(sCube, sView, vDimName, sSubset);
vIndexDim = vIndexDim +1;
END;
-
- MVP
- Posts: 3114
- Joined: Mon Dec 29, 2008 6:26 pm
- OLAP Product: TM1, Jedox
- Version: PAL 2.0.9.18
- Excel Version: Microsoft 365
- Location: Brussels, Belgium
- Contact:
Re: SubsetElementInsert - all items under roll up
If you do SubsetCreate in the code followed by SubsetCreateByMDX (on the same dimension and subset), it will fail.
Best regards,
Wim Gielis
IBM Champion 2024
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
Wim Gielis
IBM Champion 2024
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
-
- MVP
- Posts: 3114
- Joined: Mon Dec 29, 2008 6:26 pm
- OLAP Product: TM1, Jedox
- Version: PAL 2.0.9.18
- Excel Version: Microsoft 365
- Location: Brussels, Belgium
- Contact:
Re: SubsetElementInsert - all items under roll up
Revised coding:
However, if you are unfamiliar with writing TI code, please consider Bedrock.
Also, adding dimensions at N-level is not needed strictly speaking, so the loop could be greatly simplified and even removed.
Code: Select all
# cube info
sCube = 'FINDW_Ledger';
sSubset = 'source_transfer_ledger_to_obm_actuals_subset';
sView = 'source_transfer_ledger_to_obm_view';
#Recreate the Source View
ViewDestroy(sCube,sView);
ViewCreate(sCube, sView);
CubeSetLogChanges(tCube, 0);
######## Create other subsets and Source View#########
vIndexDim = 1;
WHILE(TABDIM(sCube, vIndexDim) @<> '');
vDimName = TABDIM(sCube, vIndexDim);
SubsetDestroy(vDimName,sSubset);
# Create and add elements
# Adding boundaries onto subsets
IF (vDimName @= 'FINDW_Account');
sMDX = '{TM1FILTERBYLEVEL( TM1DRILLDOWNMEMBER( {[' | vDimName | '].[N02PNL], [' | vDimName | '].[N02BUD]}, ALL, RECURSIVE), 0)}';
ELSE;
sMDX = '{TM1FILTERBYLEVEL( TM1SUBSETALL( [' | vDimName | ']), 0)}';
ENDIF;
SubsetCreateByMDX(sSubset, sMDX);
ViewSubsetAssign(sCube, sView, vDimName, sSubset);
vIndexDim = vIndexDim + 1;
END;
However, if you are unfamiliar with writing TI code, please consider Bedrock.
Also, adding dimensions at N-level is not needed strictly speaking, so the loop could be greatly simplified and even removed.
Best regards,
Wim Gielis
IBM Champion 2024
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
Wim Gielis
IBM Champion 2024
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
-
- Regular Participant
- Posts: 194
- Joined: Thu May 30, 2013 1:41 pm
- OLAP Product: Cognos
- Version: Planning Analytics 2.0.7
- Excel Version: 2010
Re: SubsetElementInsert - all items under roll up
Dear Wim,
Thanks for the revised code.
Can I ask a simple question?
Does it mean that if I'm using MDX in a loop to add subsets, I should use MDX for other dimensions (if I want to add specific group) as well instead of subsetelementinsert?
Kenneth
Thanks for the revised code.
Can I ask a simple question?
Does it mean that if I'm using MDX in a loop to add subsets, I should use MDX for other dimensions (if I want to add specific group) as well instead of subsetelementinsert?
Kenneth
-
- MVP
- Posts: 3114
- Joined: Mon Dec 29, 2008 6:26 pm
- OLAP Product: TM1, Jedox
- Version: PAL 2.0.9.18
- Excel Version: Microsoft 365
- Location: Brussels, Belgium
- Contact:
Re: SubsetElementInsert - all items under roll up
You can decide subset by subset if you use SubsetCreateByMDX or SubsetCreate/SubsetElementInsert.
Best regards,
Wim Gielis
IBM Champion 2024
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
Wim Gielis
IBM Champion 2024
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
-
- Regular Participant
- Posts: 194
- Joined: Thu May 30, 2013 1:41 pm
- OLAP Product: Cognos
- Version: Planning Analytics 2.0.7
- Excel Version: 2010
Re: SubsetElementInsert - all items under roll up
OK. I'll trying implementing it.
Thanks!
Thanks!
-
- Regular Participant
- Posts: 194
- Joined: Thu May 30, 2013 1:41 pm
- OLAP Product: Cognos
- Version: Planning Analytics 2.0.7
- Excel Version: 2010
Re: SubsetElementInsert - all items under roll up
Hi Wim,
I started working on it yesterday and yes it's working now!
Thanks a lot!
Kenneth
I started working on it yesterday and yes it's working now!
Thanks a lot!
Kenneth
-
- MVP
- Posts: 3114
- Joined: Mon Dec 29, 2008 6:26 pm
- OLAP Product: TM1, Jedox
- Version: PAL 2.0.9.18
- Excel Version: Microsoft 365
- Location: Brussels, Belgium
- Contact:
Re: SubsetElementInsert - all items under roll up
Good news, well done !kenship wrote:Hi Wim,
I started working on it yesterday and yes it's working now!
Thanks a lot!
Kenneth
Best regards,
Wim Gielis
IBM Champion 2024
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
Wim Gielis
IBM Champion 2024
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