Testing for Elements using wildcard chars

Post Reply
hbell
Posts: 61
Joined: Wed Feb 25, 2009 6:15 pm
Version: 9.1 SP3
Excel Version: 11.8

Testing for Elements using wildcard chars

Post by hbell »

Version 9.1.3

I have a TI process that needs to test for the presence in a dimension of elements that match a pattern (eg: "210EXAFR*"). I cannot use DIMIX because that requires a complete element name - and I have no way of predicting what the balance of the element name might be. I have tried to use the TI function to create a Subset using MDX in the hope that I could then measure the Subsiz ... but if there is nothing matching my string this just seems to return an error which causes my process to crash (and I'm not aware of a means of error-trapping in a TI process).

Anyone know a way around that?

thanks ...........hugh
User avatar
John Hobson
Site Admin
Posts: 330
Joined: Sun May 11, 2008 4:58 pm
OLAP Product: Any
Version: 1.0
Excel Version: 2020
Location: Lytham UK
Contact:

Re: Testing for Elements using wildcard chars

Post by John Hobson »

I may be missing something here but can you not just cycle through the dimension elements using a counter

Then have a variable like

sTest = Dimnm(Dim, Counter)

Then use string rules to test if the the first 8 characters of sTest are equal to "210EXAFR".

If so drop them into a subset.

Looks like it should work to me.
John Hobson
The Planning Factory
lotsaram
MVP
Posts: 3698
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Testing for Elements using wildcard chars

Post by lotsaram »

I can see 2 possible solutions to your problem:

1/ Insert a temporary element into your dimension that contains your search string, eg. "210EXAFR_ztemp_delete", then create your MDX subset, test for subset size, subtract one then delete the temp element from the dimension

2/ Abandon SubsetCreateByMDX approach and loop through the dimension testing each element with SCAN and incrementing your count whenever SCAN is non-zero

Either one of these approaches will work but the first is probably faster. If SubsetCreateByMDX returns a null set this is interpreted by TI as a major error and the process will terminate. The most effective way to trap this error is to ensure that the subset has at least one member.
hbell
Posts: 61
Joined: Wed Feb 25, 2009 6:15 pm
Version: 9.1 SP3
Excel Version: 11.8

Re: Testing for Elements using wildcard chars

Post by hbell »

... thanks for the responses. I had resisted the scan approach as the dimension could easily get into the 10s of 1,000s and I was concerned about response times. However, it probably is the safest route. Adding the deletable dummy element is ingenious. I had wondered whether the MDX line could be put into its own process and whether the calling process would then be able to trap a failed return without the whole thing going belly-up ..
Wim Gielis
MVP
Posts: 3223
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: Testing for Elements using wildcard chars

Post by Wim Gielis »

hbell wrote:... thanks for the responses. I had resisted the scan approach as the dimension could easily get into the 10s of 1,000s and I was concerned about response times. However, it probably is the safest route. Adding the deletable dummy element is ingenious. I had wondered whether the MDX line could be put into its own process and whether the calling process would then be able to trap a failed return without the whole thing going belly-up ..
Hi

When a dimension contains a lot of members, you may want to try out some tricks (don't know whether they're faster than a simple loop though). Lotsaram's first suggestion is the best, though.

- create a (temporary) subset that you delete afterwards, containing the elements that match the first letter for instance. This could possibly reduce the number of iterations in the loop greatly. Don't know if this helps.
- IF there's some kind of logic in the creation of elements, you may want to loop backwards (descending on index number). This has helped me once to greatly reduce the execution time of a loop.
- if sorting the elements in the dimension is not an issue in this case, you could first sort the elements, and escape the loop whenever appropriate.

HTH,

Wim
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
Post Reply