Subset Element Exists
Subset Element Exists
Hi all,
Is there such a TI function as SUBSETELEMENTEXISTS or similar. I've checked the help files and can't find anything.
Is there a way round this in TI, without using DIMIX?
Cheers,
Matt
Is there such a TI function as SUBSETELEMENTEXISTS or similar. I've checked the help files and can't find anything.
Is there a way round this in TI, without using DIMIX?
Cheers,
Matt
- 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: Subset Element Exists
You could use a while loop with the functions SubsetGetSize and SubsetGetElementName.
Martin
Code: Select all
top=SubsetGetSize('Dim', 'Sub');
count=0;
SubElemExists=0;
while(count<top);
if(SubsetGetElementName('Dim', 'Sub', count)@=soughtElement);
SubElemExists=1;
endif;
count=count+1;
end;
Last edited by Martin Ryan on Fri Sep 19, 2008 9:21 am, edited 1 time in total.
Reason: Forgot to add the "count+1";
Reason: Forgot to add the "count+1";
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
Jodi Ryan Family Lawyer
- bihints.com
- Posts: 52
- Joined: Tue May 20, 2008 8:56 am
- OLAP Product: TM1
- Version: 9.0.3
- Excel Version: 2003
- Contact:
Re: Subset Element Exists
use MDX
SubsetCreateByMDX('Subset 2','{EXCEPT( {[dim].[Subset 1]}, {[dim].[element1]} )}');
then compare the sizes of 'Subset 1' and 'Subset 2' with SubsetGetSize
if both subsets are the same size then it means element1 is not in 'Subset 1'.
SubsetCreateByMDX('Subset 2','{EXCEPT( {[dim].[Subset 1]}, {[dim].[element1]} )}');
then compare the sizes of 'Subset 1' and 'Subset 2' with SubsetGetSize
if both subsets are the same size then it means element1 is not in 'Subset 1'.
Re: Subset Element Exists
Thanks Martin,
Whereabouts in the code should I put the SUBSETELEMENTINSERT function?
Cheers,
Matt
Whereabouts in the code should I put the SUBSETELEMENTINSERT function?
Cheers,
Matt
- 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: Subset Element Exists
At the end, like so...
Code: Select all
top=SubsetGetSize('Dim', 'Sub');
count=0;
SubElemExists=0;
while(count<top);
if(SubsetGetElementName('Dim', 'Sub', count)@=soughtElement);
SubElemExists=1;
endif;
count=count+1;
end;
# If element wasn't found in the subset already, then add it in.
if(SubElemExists)=0;
SubsetElementInsert('Dim', 'sub', soughtElement, 1);
endif;
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
Jodi Ryan Family Lawyer
Re: Subset Element Exists
Nearly there . . . .
Count = 1, instead of Count = 0, but the last element in my list is entered into the subset twice, any ideas why?
TIA
Matt
Count = 1, instead of Count = 0, but the last element in my list is entered into the subset twice, any ideas why?
TIA
Matt
Re: Subset Element Exists
Moving up count = count + 1 :
top=SubsetGetSize('Dim', 'Sub');
count=1;
SubElemExists=0;
while(count<top);
count=count+1;
if(SubsetGetElementName('Dim', 'Sub', count)@=soughtElement);
SubElemExists=1;
endif;
end;
# If element wasn't found in the subset already, then add it in.
if(SubElemExists)=0;
SubsetElementInsert('Dim', 'sub', soughtElement, 1);
endif;
This means that ONLY the last element of the list is added to the subset. Still not quite right.
top=SubsetGetSize('Dim', 'Sub');
count=1;
SubElemExists=0;
while(count<top);
count=count+1;
if(SubsetGetElementName('Dim', 'Sub', count)@=soughtElement);
SubElemExists=1;
endif;
end;
# If element wasn't found in the subset already, then add it in.
if(SubElemExists)=0;
SubsetElementInsert('Dim', 'sub', soughtElement, 1);
endif;
This means that ONLY the last element of the list is added to the subset. Still not quite right.
-
- Site Admin
- Posts: 6643
- 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: Subset Element Exists
I don't think that you should have movedMattyG wrote:Moving up count = count + 1 :
top=SubsetGetSize('Dim', 'Sub');
count=1;
SubElemExists=0;
while(count<top);
count=count+1;
if(SubsetGetElementName('Dim', 'Sub', count)@=soughtElement);
SubElemExists=1;
endif;
end;
# If element wasn't found in the subset already, then add it in.
if(SubElemExists)=0;
SubsetElementInsert('Dim', 'sub', soughtElement, 1);
endif;
This means that ONLY the last element of the list is added to the subset. Still not quite right.
count=count+1;
up there; it means that you're ignoring the 1st element in the subset.
(Also 1 minor tweak that I'd suggest;
Code: Select all
if(SubsetGetElementName('Dim', 'Sub', count)@=soughtElement);
SubElemExists=1;
count = top;
endif;
But as to your actual problem... you ARE doing this on the Metadata tab and not one of the others, yes?
"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.
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Re: Subset Element Exists
Hi Alan,
This is the code as it stands, which does what I want it to do. Moving the Count = Count + 1 up just puts the last element in the list into the subset.
I have put + 1 on the end of Top = SUBSETGETSIZE ( ' Dim ', ' Sub ' ), because without it the last element in the list is added twice into the subset.
I was doing all this on the Data tab, but I've just tried moving it to the Metadata tab, and the results are the same.
IF ( SUBSETEXISTS ( ' Dim ', ' Sub ' ) = 0 ) ;
SUBSETCREATE ( ' Dim ', ' Sub ' ) ;
ENDIF ;
Top = SUBSETGETSIZE ( ' Dim ', ' Sub ' ) + 1 ;
Count = 1 ;
SubsetElementExists = 0 ;
WHILE ( Count < Top ) ;
IF ( SUBSETGETELEMENTNAME ( ' Dim ', ' Sub ', Count ) @= SoughtElement) ;
SubsetElementExists = 1 ;
Count = Top ;
ENDIF ;
Count = Count + 1 ;
END ;
IF ( SubsetElementExists = 0 ) ;
SUBSETELEMENTINSERT ( ' Dim ', ' Sub ', SoughtElement, 1 ) ;
ENDIF ;
However, I would still like to incorporate the functionality of rebuilding the subset each time the process is run. Any ideas?
Cheers,
Matt
This is the code as it stands, which does what I want it to do. Moving the Count = Count + 1 up just puts the last element in the list into the subset.
I have put + 1 on the end of Top = SUBSETGETSIZE ( ' Dim ', ' Sub ' ), because without it the last element in the list is added twice into the subset.
I was doing all this on the Data tab, but I've just tried moving it to the Metadata tab, and the results are the same.
IF ( SUBSETEXISTS ( ' Dim ', ' Sub ' ) = 0 ) ;
SUBSETCREATE ( ' Dim ', ' Sub ' ) ;
ENDIF ;
Top = SUBSETGETSIZE ( ' Dim ', ' Sub ' ) + 1 ;
Count = 1 ;
SubsetElementExists = 0 ;
WHILE ( Count < Top ) ;
IF ( SUBSETGETELEMENTNAME ( ' Dim ', ' Sub ', Count ) @= SoughtElement) ;
SubsetElementExists = 1 ;
Count = Top ;
ENDIF ;
Count = Count + 1 ;
END ;
IF ( SubsetElementExists = 0 ) ;
SUBSETELEMENTINSERT ( ' Dim ', ' Sub ', SoughtElement, 1 ) ;
ENDIF ;
However, I would still like to incorporate the functionality of rebuilding the subset each time the process is run. Any ideas?
Cheers,
Matt