Parameterized MDX
-
- Posts: 13
- Joined: Thu Aug 22, 2024 3:13 pm
- OLAP Product: IBM Planning Analytics TM1
- Version: 2.0.90
- Excel Version: Version 2405
Parameterized MDX
Hi experts,
I have simple MDX to be filtered by a wildcard which needs to be parameterized within a process.
The result should be as below where we are filtering by level zero for consolidation 'Total' and then doing a wildcard search for 'GL' in those elements.
{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [ Account ].[Total] ) } , 0)}, "*GL*" )}
The one modified to use parameter is giving errors , mabe putting "*GL*" in quotes is causing the syntax error
{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [ Account].[Total] ) } , 0)}, ' "* '| pAccount |' *" ')}
Please guide how fix this MDX for a wildcard search 'GL' which will be a parameter 'pAccount' to be entered while running the TI process.
I have been playing around the quotes and concatenation for long.
Thanks in advance.
I have simple MDX to be filtered by a wildcard which needs to be parameterized within a process.
The result should be as below where we are filtering by level zero for consolidation 'Total' and then doing a wildcard search for 'GL' in those elements.
{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [ Account ].[Total] ) } , 0)}, "*GL*" )}
The one modified to use parameter is giving errors , mabe putting "*GL*" in quotes is causing the syntax error
{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [ Account].[Total] ) } , 0)}, ' "* '| pAccount |' *" ')}
Please guide how fix this MDX for a wildcard search 'GL' which will be a parameter 'pAccount' to be entered while running the TI process.
I have been playing around the quotes and concatenation for long.
Thanks in advance.
-
- 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: Parameterized MDX
Here you can use Expand to generate a string which contains double quotes.
TM1FILTERBYPATTERN also has an argument for the attribute to search in. Otherwise you will be searching the principal name.
The Descendants function can already return only leaves so no need to wrap in FilterByLevel.
Even though your Account dimension might not have hierarchies it's better practice to future proof code by referring to the hierarchy not just the dimension.
e.g. assuming your Account dimension has an attribute called Description and that's where you want to search.
TM1FILTERBYPATTERN also has an argument for the attribute to search in. Otherwise you will be searching the principal name.
The Descendants function can already return only leaves so no need to wrap in FilterByLevel.
Even though your Account dimension might not have hierarchies it's better practice to future proof code by referring to the hierarchy not just the dimension.
e.g. assuming your Account dimension has an attribute called Description and that's where you want to search.
Code: Select all
Expand('{TM1FILTERBYPATTERN( {Descendants( [ Account ].[Account].[Total], [ Account ].[Account].Levels.Count, LEAVES )}, "*%pSearchString%*", "Description" )}')
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
- gtonkin
- MVP
- Posts: 1254
- Joined: Thu May 06, 2010 3:03 pm
- OLAP Product: TM1
- Version: Latest and greatest
- Excel Version: Office 365 64-bit
- Location: JHB, South Africa
- Contact:
Re: Parameterized MDX
You need to assign the whole MDX statement to a string variable e.g.
You could also try reduce the complexity of the quotes by using the Expand() function:
There are pros and cons - Depending on what I am doing, the first example may be better as the colouring in PAW shows variables distinct from text.
If you use Expand() and you spelled the variable incorrectly, you only pick that up at runtime.
Edit: only saw Lotsa’s reply after posting this. What he said…
Code: Select all
sMDX='{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [ Account].[Total] ) } , 0)}, "* ' | pAccount | ' *" )}';
Code: Select all
sMDX=Expand('{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [ Account].[Total] ) } , 0)}, "*%pAccount%*" )}');
If you use Expand() and you spelled the variable incorrectly, you only pick that up at runtime.
Edit: only saw Lotsa’s reply after posting this. What he said…
Last edited by gtonkin on Wed Aug 28, 2024 6:59 pm, edited 1 time in total.
-
- Posts: 13
- Joined: Thu Aug 22, 2024 3:13 pm
- OLAP Product: IBM Planning Analytics TM1
- Version: 2.0.90
- Excel Version: Version 2405
Re: Parameterized MDX
lotsaram wrote: ↑Wed Aug 28, 2024 6:18 pm Here you can use Expand to generate a string which contains double quotes.
TM1FILTERBYPATTERN also has an argument for the attribute to search in. Otherwise you will be searching the principal name.
The Descendants function can already return only leaves so no need to wrap in FilterByLevel.
Even though your Account dimension might not have hierarchies it's better practice to future proof code by referring to the hierarchy not just the dimension.
e.g. assuming your Account dimension has an attribute called Description and that's where you want to search.Code: Select all
Expand('{TM1FILTERBYPATTERN( {Descendants( [ Account ].[Account].[Total], [ Account ].[Account].Levels.Count, LEAVES )}, "*%pSearchString%*", "Description" )}')
Thanks Lotsaram.
Understood that no need for FilterByLevel if Descendants is used.
We don't have any hierarchies here and we are not using PAW. Just filtering on the principle name and not on any attribute.
Still getting syntax error on this one. Please guide.
vMDX = ' Expand ( '{TM1FILTERBYPATTERN( {Descendants( [' | dimName | '].[Total], [' | dimName | '].[' | dimName | ']. Levels.Count, LEAVES) } , "*%pAccount%*")} ' ) ' ;
-
- Posts: 13
- Joined: Thu Aug 22, 2024 3:13 pm
- OLAP Product: IBM Planning Analytics TM1
- Version: 2.0.90
- Excel Version: Version 2405
Re: Parameterized MDX
Thank you gtonkingtonkin wrote: ↑Wed Aug 28, 2024 6:23 pm You need to assign the whole MDX statement to a string variable e.g.You could also try reduce the complexity of the quotes by using the Expand() function:Code: Select all
sMDX='{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [ Account].[Total] ) } , 0)}, "* ' | pAccount | ' *" )}';
There are pros and cons - Depending on what I am doing, the first example may be better as the colouring in PAW shows variables distinct from text.Code: Select all
sMDX=Expand('{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [ Account].[Total] ) } , 0)}, "*%pAccount%*" )}');
If you use Expand() and you spelled the variable incorrectly, you only pick that up at runtime.
Edit: only saw Lotsa’s reply after posting this. What he said…

This Worked .
vMDX= Expand('{TM1FILTERBYPATTERN( {Descendants( [' | dimName | '].[Total] ) } , "*%pAccount%*" )}');
- gtonkin
- MVP
- Posts: 1254
- Joined: Thu May 06, 2010 3:03 pm
- OLAP Product: TM1
- Version: Latest and greatest
- Excel Version: Office 365 64-bit
- Location: JHB, South Africa
- Contact:
Re: Parameterized MDX
Glad it worked but would encourage you to put some time into what Lotsa said in terms of fully qualifying members with dimension and hierarchy. This could also be done using [%Dim%].[%Hier%].[…] style syntax and leveraging Expand() too, just like with the parameter.
Additionally, the 3rd parameter is also something to read up on as many search on a wildcard which is actually part of the description and the results are not returned as the principal name is what is actually being searched, as Lotsa stated.
Additionally, the 3rd parameter is also something to read up on as many search on a wildcard which is actually part of the description and the results are not returned as the principal name is what is actually being searched, as Lotsa stated.
-
- Posts: 13
- Joined: Thu Aug 22, 2024 3:13 pm
- OLAP Product: IBM Planning Analytics TM1
- Version: 2.0.90
- Excel Version: Version 2405
Re: Parameterized MDX
Thank you to both of you. - Lotsaram and gtonkin
I will try to put the Hierarchy kinda MDX also which Lotsaram mentioned .
This one Worked .
vMDX= Expand('{TM1FILTERBYPATTERN( {Descendants( [' | dimName | '].[Total] ) } , "*%pAccount%*" )}');
But,
These did not work (did not render any element in the dimension)so I used the one above.I guess then for wildcard filter Expand is the only option.
vMDX='{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [' | dimName | '].[Total] ) } , 0)}, "* ' | pAccount | ' *" )}';
vMDX='{TM1FILTERBYPATTERN( {Descendants( [' | dimName | '].[ Total] ) }, "* ' | pAccount | ' *" )}';
I will try to put the Hierarchy kinda MDX also which Lotsaram mentioned .
This one Worked .
vMDX= Expand('{TM1FILTERBYPATTERN( {Descendants( [' | dimName | '].[Total] ) } , "*%pAccount%*" )}');
But,
These did not work (did not render any element in the dimension)so I used the one above.I guess then for wildcard filter Expand is the only option.
vMDX='{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [' | dimName | '].[Total] ) } , 0)}, "* ' | pAccount | ' *" )}';
vMDX='{TM1FILTERBYPATTERN( {Descendants( [' | dimName | '].[ Total] ) }, "* ' | pAccount | ' *" )}';
- gtonkin
- MVP
- Posts: 1254
- Joined: Thu May 06, 2010 3:03 pm
- OLAP Product: TM1
- Version: Latest and greatest
- Excel Version: Office 365 64-bit
- Location: JHB, South Africa
- Contact:
Re: Parameterized MDX
Are there spaces between the asterisks and the single quotes? Cannot see on my phone but if there are you are filtering based on something containing a space before and after…
-
- 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: Parameterized MDX
Both options should work, probably like George said it’s the extra spaces.Nance1234 wrote: ↑Wed Aug 28, 2024 7:37 pm These did not work (did not render any element in the dimension)so I used the one above.I guess then for wildcard filter Expand is the only option.
vMDX='{TM1FILTERBYPATTERN( {TM1FILTERBYLEVEL( {Descendants( [' | dimName | '].[Total] ) } , 0)}, "* ' | pAccount | ' *" )}';
vMDX='{TM1FILTERBYPATTERN( {Descendants( [' | dimName | '].[ Total] ) }, "* ' | pAccount | ' *" )}';
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
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
-
- 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: Parameterized MDX
I don't think you really understood the concept of using Expand here.
You EITHER use expand to build the whole string converting variable names to their value by wrapping with %
OR you use the pipe symbol to do the concatenation.
You don't use pipes within the Expand, because what is there is just a literal string except for text between %%.
You EITHER use expand to build the whole string converting variable names to their value by wrapping with %
OR you use the pipe symbol to do the concatenation.
You don't use pipes within the Expand, because what is there is just a literal string except for text between %%.
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
-
- Posts: 13
- Joined: Thu Aug 22, 2024 3:13 pm
- OLAP Product: IBM Planning Analytics TM1
- Version: 2.0.90
- Excel Version: Version 2405
Re: Parameterized MDX
Got it Lotsaram. Thank you for pointing that out.lotsaram wrote: ↑Thu Aug 29, 2024 8:29 am I don't think you really understood the concept of using Expand here.
You EITHER use expand to build the whole string converting variable names to their value by wrapping with %
OR you use the pipe symbol to do the concatenation.
You don't use pipes within the Expand, because what is there is just a literal string except for text between %%.
Last edited by Nance1234 on Tue Sep 03, 2024 3:29 pm, edited 1 time in total.
-
- Posts: 13
- Joined: Thu Aug 22, 2024 3:13 pm
- OLAP Product: IBM Planning Analytics TM1
- Version: 2.0.90
- Excel Version: Version 2405
Re: Parameterized MDX
Thank you all. Sorry for the late reply.
Yes , both options work.
Thanks again George ,Wim and Lotsaram
Yes , both options work.
Thanks again George ,Wim and Lotsaram