MDX question

Post Reply
Marioler
Posts: 12
Joined: Tue Feb 26, 2013 10:08 am
OLAP Product: TM1
Version: PA local 2.0.8
Excel Version: 2016

MDX question

Post by Marioler »

Hello all,

I wonder if someone can help me out with a MDX. I tried with the help of the MDX primer and Wim's MDX site but I failed.

I have a cube with months as columns. Month 04 and 08 have values, all other months are 0. Is there a way with MDX to show the last month with values (08) and all months before that (01-07)?

Capture1.PNG
Capture1.PNG (4.27 KiB) Viewed 5190 times

So as a result the MDX should show month 01-08.

Capture2.PNG
Capture2.PNG (2.74 KiB) Viewed 5190 times

Is there a way to achieve that with MDX?

Regards,
Mario
User avatar
paulsimon
MVP
Posts: 808
Joined: Sat Sep 03, 2011 11:10 pm
OLAP Product: TM1
Version: PA 2.0.5
Excel Version: 2016
Contact:

Re: MDX question

Post by paulsimon »

Hi Mario

If the last month with data is random then there is certainly no easy bit of MDX that will do this. However, what is the business logic here? I am guessing that period 08 is your current period and therefore you want to show all periods up to this regardless of whether they have actuals, but don't want to show future periods that cannot possibly have actuals?

If that guess is right then the easiest approach is to have a subset that selects all periods up to and including the current one. You can then quote that on the columns of the MDX select statement as [Dimension].[Subset Name], or if you just want this in a conventional Native View then use that subset on the columns of your view. You can either define that subset using MDX, or just update a static subset to have the right periods in your month end rollover process.Either way you will probably need a reference cube of some sort to hold the current period, if you haven't got one already.

If you check my website www.successcubed.co.uk there is a link to a time dimension generator and related processes. Even if you don't use that, it should give you clues as to how to create YTD consolidations for any period, which then makes it easy to expand out to get the periods up to that point in the year. There are some examples around subsets, although not the full set as that would entail publishing too much in the way of background code and cubes.

Regards

Paul Simon
User avatar
PavoGa
MVP
Posts: 617
Joined: Thu Apr 18, 2013 6:59 pm
OLAP Product: TM1
Version: 10.2.2 FP7, PA2.0.9.1
Excel Version: 2013 PAW
Location: Charleston, Tennessee

Re: MDX question

Post by PavoGa »

What is the structure of your period dimension? In other words, do the months rollup to quarters/years/etc?
Ty
Cleveland, TN
User avatar
PavoGa
MVP
Posts: 617
Joined: Thu Apr 18, 2013 6:59 pm
OLAP Product: TM1
Version: 10.2.2 FP7, PA2.0.9.1
Excel Version: 2013 PAW
Location: Charleston, Tennessee

Re: MDX question

Post by PavoGa »

This may look like a boat load of ugly, but it will do what you are asking in your op.

This query assumes you have only one level above the periods, say "Total Year".

Code: Select all

PERIODSTODATE( [Manad].[Level000],
    TM1MEMBER( TAIL( FILTER( [Manad].[Total Year].children,
        [cubename].([z.TestRowEntryList].[R01]) > 0), 1).item(0), 0))
 


Where Level000 = the level that "Total Year" is. Level001 = the periods. I hope that is clear. This actually may work with Level000 if you have no parent for the periods.
Ty
Cleveland, TN
declanr
MVP
Posts: 1815
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: MDX question

Post by declanr »

PavoGa wrote: Wed Mar 10, 2021 9:06 pm This may look like a boat load of ugly, but it will do what you are asking in your op.

This query assumes you have only one level above the periods, say "Total Year".

Code: Select all

PERIODSTODATE( [Manad].[Level000],
    TM1MEMBER( TAIL( FILTER( [Manad].[Total Year].children,
        [cubename].([z.TestRowEntryList].[R01]) > 0), 1).item(0), 0))
 


Where Level000 = the level that "Total Year" is. Level001 = the periods. I hope that is clear. This actually may work with Level000 if you have no parent for the periods.
That's a lovely bit of MDX and I think you undersell it by pointing out that it is dependent on levels etc.
The core logic you have come up with is to find the first or last element from a filtered set and converting the single element set to a member.
Once you get to the point of having [Manad].[08] as a member there are dozens of ways to convert it to the range of [Manad].[01]:[Manad].[08]

I would say the combination of TM1Member and Tail (or Head) is the perfect trick. What goes inside and outside of those 2 sections is the trivial bit.
Declan Rodger
Wim Gielis
MVP
Posts: 3113
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: MDX question

Post by Wim Gielis »

For those of you reading the topic and the suggested nice (!) MDX formula of PeriodsToDate;
this formula can also be used in dimensions (hierarchies) that are not dealing with Time or Periods.
So Accounts, Cost Centers, Companies, ... though of course it still has to make sense.

For the MDX given, if you do not want to use the }HierarchyProperties cube and a TI process to set level names, an alternative:

Code: Select all

PERIODSTODATE( [Manad].[Total Year].Level, TM1MEMBER( TAIL( 
FILTER( [Manad].[Total Year].children, [cubename].([z.TestRowEntryList].[R01]) > 0), 1).item(0), 0))
whereby "Total Year" is the name of the parent of the individual periods.
Best regards,

Wim Gielis

IBM Champion 2024
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
User avatar
gtonkin
MVP
Posts: 1199
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: MDX question

Post by gtonkin »

Have to agree with Declan - great code Ty!

@Alan - a like button would be great in these situations :)
Mark RMBC
Community Contributor
Posts: 292
Joined: Tue Sep 06, 2016 7:55 am
OLAP Product: TM1
Version: 10.1.1
Excel Version: Excel 2010

Re: MDX question

Post by Mark RMBC »

This gets a thumbs up from me too.

Just to illustrate what Declan said about the trick being tm1member and Tail, this would work too:

Code: Select all

LASTPERIODS(99, TM1MEMBER( TAIL( FILTER( [Manad].[Total Year].children, NOT(ISEMPTY([cubename].([z.TestRowEntryList].[R01])))), 1).item(0), 0))
But I would certainly go with PavoGa's ingenious suggestion.

regards,

Mark
Marioler
Posts: 12
Joined: Tue Feb 26, 2013 10:08 am
OLAP Product: TM1
Version: PA local 2.0.8
Excel Version: 2016

Re: MDX question

Post by Marioler »

Hello everyone!

Thanks so much for all the great input and comments.

Special thanks of course to Ty and Wim.
@Ty: Big thank you, this was exactly what I needed. And I agree with the others - great code.
@Wim: I went with your version (without being dependant on the }HierarchyProperties cube), thanks for the alternative.

Really happy now :-)

Regards,
Mario
User avatar
PavoGa
MVP
Posts: 617
Joined: Thu Apr 18, 2013 6:59 pm
OLAP Product: TM1
Version: 10.2.2 FP7, PA2.0.9.1
Excel Version: 2013 PAW
Location: Charleston, Tennessee

Re: MDX question

Post by PavoGa »

Marioler wrote: Thu Mar 11, 2021 4:09 pm Hello everyone!

Thanks so much for all the great input and comments.

Special thanks of course to Ty and Wim.
@Ty: Big thank you, this was exactly what I needed. And I agree with the others - great code.
@Wim: I went with your version (without being dependant on the }HierarchyProperties cube), thanks for the alternative.

Really happy now :-)

Regards,
Mario
You're welcome and I would have used Wim's flavor of it as well. ;)
Ty
Cleveland, TN
Wim Gielis
MVP
Posts: 3113
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: MDX question

Post by Wim Gielis »

PavoGa wrote: Thu Mar 11, 2021 6:36 pmYou're welcome and I would have used Wim's flavor of it as well. ;)
Without yours it would have been 12 nested IF's for me. Or a rule that is then used in the MDX ! :lol:
Best regards,

Wim Gielis

IBM Champion 2024
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