Insert ALL N element into subset

Post Reply
hyunjia
Posts: 64
Joined: Fri Jul 27, 2012 4:13 pm
OLAP Product: TM1
Version: 2010
Excel Version: Excel 2010

Insert ALL N element into subset

Post by hyunjia »

During the process of zero out data in cube, it occurs to me that I can only create a subset of all N element by MDX(dynamic) . Is there other way to include all N element in the subset ? Of course you can loop all element and determine if it's N element, but that's not the way I wanted . I have double-check with the TM1 reference but can't the answer.

Probably this should be a very simple question, thank you :oops:
User avatar
qml
MVP
Posts: 1096
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: Insert ALL N element into subset

Post by qml »

Why, are dynamic subsets not to your liking?

The quickest way I can think of would be to:
a) create the dynamic subset using SubsetCreateByMDX();
b) use SubsetElementInsert() to insert a dummy element in that subset to implictly turn it to a static subset;
c) delete the dummy element from the subset.

And voila, you have yourself a static subset defined by whatever criteria you applied in step a.

Is that what you are after?
Kamil Arendt
David Usherwood
Site Admin
Posts: 1458
Joined: Wed May 28, 2008 9:09 am

Re: Insert ALL N element into subset

Post by David Usherwood »

Since you're trying to zero out a view, set the dimension(s) to 'All' and then set the view to skip 'calculated' (really consolidated) values.
hyunjia
Posts: 64
Joined: Fri Jul 27, 2012 4:13 pm
OLAP Product: TM1
Version: 2010
Excel Version: Excel 2010

Re: Insert ALL N element into subset

Post by hyunjia »

Thanks for the prompt reply. It just occur to me during zero out cube, but the really focus is how I can insert all N element in subset , not just for cube clearing. Essential, I have heard so many bad things about MDX subset being slower than the static subset.

Yet, it seems the MDX would be no.1 options here and then probably would need another TI to turn it into a static subset though. Are there other tricks ? :)
Wim Gielis
MVP
Posts: 3222
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: Insert ALL N element into subset

Post by Wim Gielis »

Probably a simpler idea: if a zero out view contains all leaf level elements in a dimension,
you do not have to specify it at all. That is, SubsetDestroy, SubsetCreateByMDX, ViewSubsetAssign, ...
do not have to be written out explicitly for these kind of dimensions.
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
Wim Gielis
MVP
Posts: 3222
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: Insert ALL N element into subset

Post by Wim Gielis »

hyunjia wrote:Thanks for the prompt reply. It just occur to me during zero out cube, but the really focus is how I can insert all N element in subset , not just for cube clearing. Essential, I have heard so many bad things about MDX subset being slower than the static subset.
If it's only a zero out in the Prolog tab, I don't think it will matter a lot (dynamic vs. static subset).
What is your concern? Speed, too much code, ... ?
hyunjia wrote:Yet, it seems the MDX would be no.1 options here and then probably would need another TI to turn it into a static subset though. Are there other tricks ? :)
Did you see Kamil's method? Why would you need a different TI?
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
User avatar
qml
MVP
Posts: 1096
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: Insert ALL N element into subset

Post by qml »

hyunjia wrote:Yet, it seems the MDX would be no.1 options here and then probably would need another TI to turn it into a static subset though.
The issue with MDX subsets is that they tend to recalculate themselves more often than needed and that this recalculation puts a lock on the dimension. With the solution described by me you only need 1 TI with 3 lines of code to get the desired result with only one recalculation of MDX, so it gives you the best of both worlds, really.
Kamil Arendt
Wim Gielis
MVP
Posts: 3222
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: Insert ALL N element into subset

Post by Wim Gielis »

qml wrote:Why, are dynamic subsets not to your liking?

The quickest way I can think of would be to:
a) create the dynamic subset using SubsetCreateByMDX();
b) use SubsetElementInsert() to insert a dummy element in that subset to implictly turn it to a static subset;
c) delete the dummy element from the subset.

And voila, you have yourself a static subset defined by whatever criteria you applied in step a.

Is that what you are after?
Would a zero out in the Prolog tab be faster using a-b-c versus only a ?
Is it worth coding the subset being static or not?
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
User avatar
qml
MVP
Posts: 1096
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: Insert ALL N element into subset

Post by qml »

I think you are focusing on the zeroout part too much, Wim. From what I understood the OP was asking for a more generic tip on subsets, not necessarily those used for view zeroouts.
Kamil Arendt
Wim Gielis
MVP
Posts: 3222
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: Insert ALL N element into subset

Post by Wim Gielis »

qml wrote:I think you are focusing on the zeroout part too much, Wim. From what I understood the OP was asking for a more generic tip on subsets, not necessarily those used for view zeroouts.
Ah okay, a more general discussion, then. Fine !
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
hyunjia
Posts: 64
Joined: Fri Jul 27, 2012 4:13 pm
OLAP Product: TM1
Version: 2010
Excel Version: Excel 2010

Re: Insert ALL N element into subset

Post by hyunjia »

Sure, it can be done within a TI , just my expression , it really means another sub routine :oops:
And yes, the differences between dynamic and static would relatively the same if I use them mostly in Prolog. Thanks you all , now I can sleep well and not having this problem surrounding me :lol:
Wim Gielis wrote:
hyunjia wrote:Thanks for the prompt reply. It just occur to me during zero out cube, but the really focus is how I can insert all N element in subset , not just for cube clearing. Essential, I have heard so many bad things about MDX subset being slower than the static subset.
If it's only a zero out in the Prolog tab, I don't think it will matter a lot (dynamic vs. static subset).
What is your concern? Speed, too much code, ... ?
hyunjia wrote:Yet, it seems the MDX would be no.1 options here and then probably would need another TI to turn it into a static subset though. Are there other tricks ? :)
Did you see Kamil's method? Why would you need a different TI?
hyunjia
Posts: 64
Joined: Fri Jul 27, 2012 4:13 pm
OLAP Product: TM1
Version: 2010
Excel Version: Excel 2010

Re: Insert ALL N element into subset

Post by hyunjia »

Yeah , I just put it into a broader spectrum. But I am very surprise to see so many valuable advice following up. Thank you all for being so supportive. :D
Wim Gielis wrote:
qml wrote:I think you are focusing on the zeroout part too much, Wim. From what I understood the OP was asking for a more generic tip on subsets, not necessarily those used for view zeroouts.
Ah okay, a more general discussion, then. Fine !
hyunjia
Posts: 64
Joined: Fri Jul 27, 2012 4:13 pm
OLAP Product: TM1
Version: 2010
Excel Version: Excel 2010

Re: Insert ALL N element into subset

Post by hyunjia »

I have never heard of this behavior to turn a dynamic subset into static one by SubsetElementInsert() . I think I really should get some hands-on and do my homework . Very appreciate for this one 8-)
qml wrote:Why, are dynamic subsets not to your liking?

The quickest way I can think of would be to:
a) create the dynamic subset using SubsetCreateByMDX();
b) use SubsetElementInsert() to insert a dummy element in that subset to implictly turn it to a static subset;
c) delete the dummy element from the subset.

And voila, you have yourself a static subset defined by whatever criteria you applied in step a.

Is that what you are after?
hyunjia
Posts: 64
Joined: Fri Jul 27, 2012 4:13 pm
OLAP Product: TM1
Version: 2010
Excel Version: Excel 2010

Re: Insert ALL N element into subset

Post by hyunjia »

I have done my homework and it works. However, it seems dimension could not refresh until the Prolog process completed. Is there any way to work around this problem and put all my code in Prolog. My steps would be :
1. Create a dummy element
2. Create a dynamic subset
3. Put the element into dynamic subset
4. remove it from the subset
The issue would be : I have to manually create a dummy element since the dimension could not be refresh within Prolog.

qml wrote:Why, are dynamic subsets not to your liking?

The quickest way I can think of would be to:
a) create the dynamic subset using SubsetCreateByMDX();
b) use SubsetElementInsert() to insert a dummy element in that subset to implictly turn it to a static subset;
c) delete the dummy element from the subset.

And voila, you have yourself a static subset defined by whatever criteria you applied in step a.

Is that what you are after?
User avatar
Steve Rowe
Site Admin
Posts: 2455
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: Insert ALL N element into subset

Post by Steve Rowe »

qml wrote:
Why, are dynamic subsets not to your liking?

The quickest way I can think of would be to:
a) create the dynamic subset using SubsetCreateByMDX();
b) use SubsetElementInsert() to insert a dummy element in that subset to implictly turn it to a static subset;
c) delete the dummy element from the subset.

And voila, you have yourself a static subset defined by whatever criteria you applied in step a.

Is that what you are after?
Fantastic piece of slight of hand Kamil. Thanks for sharing, you should make a post in the Useful forum

@hyunjia.

Not sure why are inserting a dummy element into the dimnesion before you start? I don't think is required.
I just insert the first element in the dimension into the first position in the subset. Then subsetelementdelete is done by index, so just delete the first element of the subset.

Cheers
Technical Director
www.infocat.co.uk
Wim Gielis
MVP
Posts: 3222
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: Insert ALL N element into subset

Post by Wim Gielis »

Creating a dummy element is not needed. All subset updates are done immediately. No looping in this code.

My test code:

Code: Select all

vDim='Projects';
vSub='test';
vFile='test_subset.cma';

If(SubsetGetSize(vDim,vSub)>0);
  SubsetElementInsert(vDim,vSub,SubsetGetElementName(vDim,vSub,1),1);
  AsciiOutput(vFile,NumberToString(SubsetGetSize(vDim,vSub)));
  SubsetElementDelete(vDim,vSub,1);
  AsciiOutput(vFile,NumberToString(SubsetGetSize(vDim,vSub)));
EndIf;
'test' is a dynamic subset containing only 1 element. So the first AsciiOutput gives 2 as the result, the second AsciiOutput gives 1, as expected.
With this code, 'test' becomes a static subset (losing its MDX expression).
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
hyunjia
Posts: 64
Joined: Fri Jul 27, 2012 4:13 pm
OLAP Product: TM1
Version: 2010
Excel Version: Excel 2010

Re: Insert ALL N element into subset

Post by hyunjia »

That is wonderful. Thanks all . The technique is elegant so smooth.

Wim Gielis wrote:Creating a dummy element is not needed. All subset updates are done immediately. No looping in this code.

My test code:

Code: Select all

vDim='Projects';
vSub='test';
vFile='test_subset.cma';

If(SubsetGetSize(vDim,vSub)>0);
  SubsetElementInsert(vDim,vSub,SubsetGetElementName(vDim,vSub,1),1);
  AsciiOutput(vFile,NumberToString(SubsetGetSize(vDim,vSub)));
  SubsetElementDelete(vDim,vSub,1);
  AsciiOutput(vFile,NumberToString(SubsetGetSize(vDim,vSub)));
EndIf;
'test' is a dynamic subset containing only 1 element. So the first AsciiOutput gives 2 as the result, the second AsciiOutput gives 1, as expected.
With this code, 'test' becomes a static subset (losing its MDX expression).
Post Reply