Find Element Index by Name in TI?

Post Reply
PlanningDev
Community Contributor
Posts: 349
Joined: Tue Aug 17, 2010 6:31 am
OLAP Product: Planning Analytics
Version: 2.0.5
Excel Version: 2016

Find Element Index by Name in TI?

Post by PlanningDev »

Is there a way to find an element index number by its name within a TI?

Im trying to create a subset that has all but one element. I thought I would use SubsetElementDelete but it wants me to provide the index of the element to be deleted. I was hoping to find this dynamically in order to avoid complications if I had elements to the dimension later on.
User avatar
Martin Ryan
Site Admin
Posts: 1989
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Re: Find Element Index by Name in TI?

Post by Martin Ryan »

Well now, that's interesting that you delete subset elements by index rather than name. That makes the missing subix function even more necessary - and evidently not that hard to do as they're already using indexes it would appear.

I've never come across it because I don't think I've ever deleted an element from an existing subset. If I was going to do that I'd just destroy the subset and rebuild it the way I wanted it from scratch.

If you really want to do it this way you'll need to use a while loop and the SubsetGetSize and SubsetGetElementName functions.

I think it'd be simpler (and faster) to just rebuild the subset the way you want it.

Martin
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer
PlanningDev
Community Contributor
Posts: 349
Joined: Tue Aug 17, 2010 6:31 am
OLAP Product: Planning Analytics
Version: 2.0.5
Excel Version: 2016

Re: Find Element Index by Name in TI?

Post by PlanningDev »

It may be faster to build it the way I need it the problem is that to be safe I really do need all elements except for one. In order to build it the way I want without using a loop would take a lot of statements.

Technically its not that big a deal for what Im doing. One of my TI's transfers data in a cube from one section to another but in one section the data is rules calculated so the error log pops back errors. Its working as intended I just didnt want end users who hit the Action button to see process failed. I guess I could change the text of that response in the action button options but I figured it better to try and learn the options within the TI process.
Alan Kirk
Site Admin
Posts: 6647
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Find Element Index by Name in TI?

Post by Alan Kirk »

PlanningDev wrote:It may be faster to build it the way I need it the problem is that to be safe I really do need all elements except for one. In order to build it the way I want without using a loop would take a lot of statements.

Technically its not that big a deal for what Im doing. One of my TI's transfers data in a cube from one section to another but in one section the data is rules calculated so the error log pops back errors. Its working as intended I just didnt want end users who hit the Action button to see process failed. I guess I could change the text of that response in the action button options but I figured it better to try and learn the options within the TI process.
Thinking laterally... why not just do an If() test for that element in your data tab and if found, ItemSkip it? Saves you needing to create a subset at all. (Not hugely efficient since you're processing an extra If() for each record, but if the data set is relatively small it should be harmless.)

Either that, or the loop to create the subset really isn't that long. Get the dimension size with DimSiz, get each element with DimNm within a While loop (while index_variable <= the length of the dimension). Assuming that you only want N levels, If(Ellev of the element =0 & the ElementName @<> the name you want to skip), add the element to the subset.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
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: Find Element Index by Name in TI?

Post by tomok »

Alan Kirk wrote:Thinking laterally... why not just do an If() test for that element in your data tab and if found, ItemSkip it? Saves you needing to create a subset at all. (Not hugely efficient since you're processing an extra If() for each record, but if the data set is relatively small it should be harmless.)
If you want to skip errors when loading to a section that may contain rule calculated values you can just encapsulate your CellPutN inside an IF statement using the CellIsUpdateable TI function. It will skip the rule calculated elements, eliminating those unwanted errors, and not cause any harm.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
captnknz
Posts: 12
Joined: Wed Jan 05, 2011 10:14 pm
OLAP Product: Tm1
Version: 13.0
Excel Version: 2016
Location: Sydney

Re: Find Element Index by Name in TI?

Post by captnknz »

You can use the DIMIX function to return the element index.
Kirk Bensemann
Alan Kirk
Site Admin
Posts: 6647
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Find Element Index by Name in TI?

Post by Alan Kirk »

captnknz wrote:You can use the DIMIX function to return the element index.
He's talking about the index within a subset, not a dimension.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Alan Kirk
Site Admin
Posts: 6647
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Find Element Index by Name in TI?

Post by Alan Kirk »

tomok wrote:
Alan Kirk wrote:Thinking laterally... why not just do an If() test for that element in your data tab and if found, ItemSkip it? Saves you needing to create a subset at all. (Not hugely efficient since you're processing an extra If() for each record, but if the data set is relatively small it should be harmless.)
If you want to skip errors when loading to a section that may contain rule calculated values you can just encapsulate your CellPutN inside an IF statement using the CellIsUpdateable TI function. It will skip the rule calculated elements, eliminating those unwanted errors, and not cause any harm.
Yes, that's probably a better idea if you go down the ItemSkip route; that way you wouldn't have to worry about changing the code should any new rules-based elements start to apply. It still means the extra If() statement each loop but unless the Data process takes a seriously long time to process and you need to optimize your speed up the yin-yang, it's ultimately easier than modifying the subset.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
CoN73mP7
Posts: 37
Joined: Wed May 18, 2011 7:48 am
OLAP Product: TM1
Version: 9.5
Excel Version: 2003
Location: Stuttgart, Germany
Contact:

Re: Find Element Index by Name in TI?

Post by CoN73mP7 »

I know my answer is a bit to late but while searching for a solution when i had the same problem, i found this script which may just do what you want:

http://code.bedrocktm1.org/cgi-bin/run. ... f41917a691
K3DubEU
Posts: 6
Joined: Tue Sep 10, 2013 3:19 pm
OLAP Product: TM1
Version: 10.2
Excel Version: 2007

Re: Find Element Index by Name in TI?

Post by K3DubEU »

Hi,

As the link from the previous post is no longer active, has anyone come across a simple solution to this?
RE: Obtaining the index number of an element within a subset

Thanks,
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: Find Element Index by Name in TI?

Post by qml »

K3DubEU wrote:As the link from the previous post is no longer active, has anyone come across a simple solution to this?
RE: Obtaining the index number of an element within a subset
You mean the solution described above by Martin? I guess you're looking for a pret-a-porter code snippet instead of an approach description then? In that case take a look here.
Kamil Arendt
Alan Kirk
Site Admin
Posts: 6647
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Find Element Index by Name in TI?

Post by Alan Kirk »

qml wrote:
K3DubEU wrote:As the link from the previous post is no longer active, has anyone come across a simple solution to this?
RE: Obtaining the index number of an element within a subset
You mean the solution described above by Martin? I guess you're looking for a pret-a-porter code snippet instead of an approach description then? In that case take a look here.
I think they were actually referring to the Bedrock link in the post immediately above, which is dead. Most likely it was to the Bedrock.Dim.Sub.Create process (URL live at the time of posting, if not in the future just Bing or Google it) which allows you to create a subset by level with specific element(s) excluded.

The problem is that it's not at all clear which "this" K3DubEU is referring to. Whether it's really searching for the index of an element in a subset (and if so, to what end?), whether it's having a subset which removes a specific element, or whether it's ignoring the upload of elements which are rule based; all have come up here as the reason for the original question were slowly revealed over time. If it's the first of these, just use Martin's code, if the second, use my suggestion or the Bedrock process, if the third use Tomok's suggestion. None of the solutions are unduly complicated.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
K3DubEU
Posts: 6
Joined: Tue Sep 10, 2013 3:19 pm
OLAP Product: TM1
Version: 10.2
Excel Version: 2007

Re: Find Element Index by Name in TI?

Post by K3DubEU »

Alan Kirk wrote:
qml wrote:
K3DubEU wrote:As the link from the previous post is no longer active, has anyone come across a simple solution to this?
RE: Obtaining the index number of an element within a subset
You mean the solution described above by Martin? I guess you're looking for a pret-a-porter code snippet instead of an approach description then? In that case take a look here.
I think they were actually referring to the Bedrock link in the post immediately above, which is dead. Most likely it was to the Bedrock.Dim.Sub.Create process (URL live at the time of posting, if not in the future just Bing or Google it) which allows you to create a subset by level with specific element(s) excluded.

The problem is that it's not at all clear which "this" K3DubEU is referring to. Whether it's really searching for the index of an element in a subset (and if so, to what end?), whether it's having a subset which removes a specific element, or whether it's ignoring the upload of elements which are rule based; all have come up here as the reason for the original question were slowly revealed over time. If it's the first of these, just use Martin's code, if the second, use my suggestion or the Bedrock process, if the third use Tomok's suggestion. None of the solutions are unduly complicated.
I was looking for a way to create a subset dynamically to include all elements but one or two. I will give the Bedrock process a shot. Thanks for the suggestions.
K3DubEU
Posts: 6
Joined: Tue Sep 10, 2013 3:19 pm
OLAP Product: TM1
Version: 10.2
Excel Version: 2007

Re: Find Element Index by Name in TI?

Post by K3DubEU »

I've decided to just use an MDX expression for the subset.

SubsetCreatebyMDX(SubName, MDX_Expression);
MDX: {EXCEPT({ },{ })}
Post Reply