Hi all.
Just completed my first attempt for an MDX expression in TM1. After a bit of reading/searching on here, I got it working. Basically I wanted to select all items in the product dimension, in consolidation 0400 that have 01-R or 02-R or 03-R in the element. I have used the union function to do this. I noticed however union seems to only union two things together at a time. is it true then that if i had say 10 different expressions to filter on then I would need UNION 9 times.
The example is;
{UNION({UNION(
{TM1FILTERBYPATTERN({TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER({ [Product].[0400] }, ALL, RECURSIVE)}, 0)} , "*01-R*")},
{TM1FILTERBYPATTERN({TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER({ [Product].[0400] }, ALL, RECURSIVE)}, 0)} , "*02-R*")} )},
{TM1FILTERBYPATTERN({TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER({ [Product].[0400] }, ALL, RECURSIVE)}, 0)} , "*03-R*")} )}
Thanks in advance.
David
MDX Union Question
-
- MVP
- Posts: 733
- Joined: Wed May 14, 2008 11:06 pm
Re: MDX Union Question
You can use the following syntax instead of nested UNIONs:
If you have subsets named the same as elements in the dimension then you may need to look into the bespoke TM1SubsetToSet function.
Edit: I should have mentioned that [dim].[subN] can be replaced by {your MDX goes here}
Code: Select all
{ [dim].[sub1], [dim].[sub2], [dim].[sub3] }
Edit: I should have mentioned that [dim].[subN] can be replaced by {your MDX goes here}
Robin Mackenzie
-
- Posts: 6
- Joined: Tue Nov 11, 2014 2:34 pm
- OLAP Product: TM1, Cognos
- Version: 9.5.2
- Excel Version: 2010
Re: MDX Union Question
David,
You could also venture a little outside of the TM1 box on this one.
With the DESCENDANTS function you can return the 0 level elements in one shot. I don't know how many levels deep your hierarchy goes but using a larger number in the second parameter (in this case I used 25) doesn't hurt. The FILTER function is great for multiple criteria, although using the INSTR function for wildcards is a bit of a pain.
The TM1 MDX recorder is great for learning MDX but, if you have time, play around with what it gives you. It's much like the Excel macro recorder...it will give you something that works but it is not always the most efficient code (especially all those braces it sticks in there).
Micheal
You could also venture a little outside of the TM1 box on this one.
Code: Select all
FILTER(DESCENDANTS([Product].[0400], 25, LEAVES), INSTR([Product].CurrentMember.Name, "01-R")>0 OR INSTR([Product].CurrentMember.Name, "02-R")>0 OR INSTR([Product].CurrentMember.Name, "03-R")>0 )
The TM1 MDX recorder is great for learning MDX but, if you have time, play around with what it gives you. It's much like the Excel macro recorder...it will give you something that works but it is not always the most efficient code (especially all those braces it sticks in there).
Micheal
-
- Community Contributor
- Posts: 324
- Joined: Mon Jul 02, 2012 9:39 pm
- OLAP Product: TM1
- Version: PAL 2.0.8
- Excel Version: 2016
- Location: Sydney, Australia
Re: MDX Union Question
Another suggestion would be to assign a new attribute for the product dimension (i.e. 01-R, etc) and then just use {Filter function to get the products you want. It would avoid having to write complex/chunky MDX statement.
The downside of this approach would be having to maintain those attributes regulary via TI.
Just a thought
The downside of this approach would be having to maintain those attributes regulary via TI.
Just a thought

-
- MVP
- Posts: 733
- Joined: Wed May 14, 2008 11:06 pm
Re: MDX Union Question
Interesting - in a dimension of a million elements and DNLEV of 5, this works a couple of seconds quicker:Headon01 wrote:You could also venture a little outside of the TM1 box on this one.
Code: Select all
DESCENDANTS([test].[root], 25, LEAVES)
Code: Select all
{TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER({ [test].[root] }, ALL, RECURSIVE)}, 0)}
It seems the distance parameter can be arbitrarily large without affecting performance. However, it should be >= DNLEV - 1 of the dimension in order to work.
Robin Mackenzie
-
- Posts: 6
- Joined: Tue Nov 11, 2014 2:34 pm
- OLAP Product: TM1, Cognos
- Version: 9.5.2
- Excel Version: 2010
Re: MDX Union Question
Robin,
Probably has to do with the two TM1-MDX functions being evaluated instead of one MS-MDX function. I would think toe-to-toe the TM1 MDXs would out perform the MS-MDXs but I have never tested that out.
As far as the levels parameter goes, when I first started using this function I would put 99 as that parameters value. When I saw that it worked the way I wanted it to I put in the actual number of dimension levels (against production data) and noticed there was no difference in performance. I usually put in the number of dimension levels + 5 into these functions.
Micheal
Probably has to do with the two TM1-MDX functions being evaluated instead of one MS-MDX function. I would think toe-to-toe the TM1 MDXs would out perform the MS-MDXs but I have never tested that out.
As far as the levels parameter goes, when I first started using this function I would put 99 as that parameters value. When I saw that it worked the way I wanted it to I put in the actual number of dimension levels (against production data) and noticed there was no difference in performance. I usually put in the number of dimension levels + 5 into these functions.
Micheal