Page 1 of 1
Find Element Index by Name in TI?
Posted: Tue Jan 11, 2011 11:35 pm
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.
Re: Find Element Index by Name in TI?
Posted: Wed Jan 12, 2011 12:30 am
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
Re: Find Element Index by Name in TI?
Posted: Wed Jan 12, 2011 12:39 am
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.
Re: Find Element Index by Name in TI?
Posted: Wed Jan 12, 2011 12:51 am
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.
Re: Find Element Index by Name in TI?
Posted: Wed Jan 12, 2011 1:21 am
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.
Re: Find Element Index by Name in TI?
Posted: Wed Jan 12, 2011 1:30 am
by captnknz
You can use the DIMIX function to return the element index.
Re: Find Element Index by Name in TI?
Posted: Wed Jan 12, 2011 2:19 am
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.
Re: Find Element Index by Name in TI?
Posted: Wed Jan 12, 2011 2:33 am
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.
Re: Find Element Index by Name in TI?
Posted: Wed Oct 26, 2011 2:33 pm
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
Re: Find Element Index by Name in TI?
Posted: Fri Nov 08, 2013 5:03 pm
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,
Re: Find Element Index by Name in TI?
Posted: Fri Nov 08, 2013 5:45 pm
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.
Re: Find Element Index by Name in TI?
Posted: Fri Nov 08, 2013 6:42 pm
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.
Re: Find Element Index by Name in TI?
Posted: Mon Nov 11, 2013 3:29 pm
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.
Re: Find Element Index by Name in TI?
Posted: Thu Nov 14, 2013 8:07 pm
by K3DubEU
I've decided to just use an MDX expression for the subset.
SubsetCreatebyMDX(SubName, MDX_Expression);
MDX: {EXCEPT({ },{ })}